diff --git a/packages/volto/src/components/manage/Widgets/TextWidget.jsx b/packages/volto/src/components/manage/Widgets/TextWidget.jsx index 4e5e41a8c8..648c59cffb 100644 --- a/packages/volto/src/components/manage/Widgets/TextWidget.jsx +++ b/packages/volto/src/components/manage/Widgets/TextWidget.jsx @@ -19,6 +19,7 @@ const TextWidget = (props) => { onBlur, onClick, icon, + focus, iconAction, minLength, maxLength, @@ -26,11 +27,13 @@ const TextWidget = (props) => { isDisabled, } = props; - const ref = useRef(); + const ref = useRef(null); useEffect(() => { - ref.current = value; - }, [value]); + if (focus) { + ref.current.focus(); + } + }, [focus]); return ( @@ -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({ @@ -89,6 +93,7 @@ TextWidget.defaultProps = { onBlur: () => {}, onClick: () => {}, icon: null, + focus: false, iconAction: null, minLength: null, maxLength: null,