Skip to content

Commit

Permalink
useRef
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishasoumya-02 committed May 16, 2024
1 parent b2f1ae0 commit ce35f82
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/volto/src/components/manage/Widgets/TextWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ const TextWidget = (props) => {
onBlur,
onClick,
icon,
focus,
iconAction,
minLength,
maxLength,
placeholder,
isDisabled,
} = props;

const ref = useRef();
const ref = useRef(null);

useEffect(() => {
ref.current = value;
}, [value]);
if (focus) {
ref.current.focus();
}
}, [focus]);

return (
<FormFieldWrapper {...props} className="text">
Expand Down Expand Up @@ -69,6 +72,7 @@ TextWidget.propTypes = {
value: PropTypes.string,
isDisabled: PropTypes.bool,
onChange: PropTypes.func,
focus: PropTypes.bool,
onBlur: PropTypes.func,
onClick: PropTypes.func,
icon: PropTypes.shape({
Expand All @@ -89,6 +93,7 @@ TextWidget.defaultProps = {
onBlur: () => {},
onClick: () => {},
icon: null,
focus: false,
iconAction: null,
minLength: null,
maxLength: null,
Expand Down

0 comments on commit ce35f82

Please sign in to comment.