Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added enterEdit callback and fixed onClick event precision #14

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const CTE = require("react-click-to-edit");
| inputClass | string | css class applied to the _input_ |
| textClass | string | css class applied to the _text_ |
| initialValue | string | initial value of text |
| startEditing | () => {} | callback invoked when entering edit mode by clicking the text |
| endEditing | (value) => {} | callback invoked when leaving edit mode by clicking ENTER or ESC |

[See elaborate examples](https://react-click-to-edit.web.app/docs-examples)
Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const ClickToEdit = props => {
const [isEditMode, setEditMode] = useState(false);

const getIntoEditMode = () => {
if (props.startEditing && !isEditMode) {
props.startEditing();
}
setEditMode(true);
};
};

const getOffEditMode = () => {
setEditMode(false);
Expand Down Expand Up @@ -36,7 +39,6 @@ const ClickToEdit = props => {
<section
data-value={value}
className={classNames("CTE--wrapper", props.wrapperClass)}
onClick={getIntoEditMode}
>
{isEditMode ? (
<input
Expand All @@ -50,7 +52,10 @@ const ClickToEdit = props => {
size="1"
/>
) : (
<span className={classNames("CTE--text", props.textClass)}>
<span
className={classNames("CTE--text", props.textClass)}
onClick={getIntoEditMode}
>
{value}
</span>
)}
Expand Down