From ce35f829ccf12b0bead628af18c57a3ce0b0951f Mon Sep 17 00:00:00 2001 From: TishaSoumya-02 Date: Thu, 16 May 2024 16:46:25 +0530 Subject: [PATCH] useRef --- .../src/components/manage/Widgets/TextWidget.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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,