Skip to content

Commit

Permalink
Merge pull request #14 from margual56/master
Browse files Browse the repository at this point in the history
Added enterEdit callback and fixed onClick event precision
  • Loading branch information
chungchiehlun committed Feb 4, 2021
2 parents d9c3bb8 + 262d447 commit 74dd097
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 74dd097

Please sign in to comment.