diff --git a/ghost/portal/src/components/common/InputField.js b/ghost/portal/src/components/common/InputField.js index 8b020721b9..576c98497c 100644 --- a/ghost/portal/src/components/common/InputField.js +++ b/ghost/portal/src/components/common/InputField.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useRef } from 'react'; import {isCookiesDisabled} from '../../utils/helpers'; export const InputFieldStyles = ` @@ -92,8 +92,10 @@ function InputField({ onKeyDown = () => {}, tabindex, maxlength, + autoFocus, errorMessage }) { + const fieldNode = useRef(null); id = id || `input-${name}`; const labelClasses = hideLabel ? 'gh-portal-input-label hidden' : 'gh-portal-input-label'; const inputClasses = errorMessage ? 'gh-portal-input error' : 'gh-portal-input'; @@ -116,6 +118,11 @@ function InputField({ default: break; } + useEffect(() => { + if (autoFocus) { + fieldNode.current.focus(); + } + }, [autoFocus]); return (
@@ -123,6 +130,7 @@ function InputField({
{ }, onKeyDown = () => {}}) onBlur={e => onBlur(e, field)} tabIndex={field.tabindex} errorMessage={field.errorMessage} + autoFocus={field.autoFocus} /> );