diff --git a/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap b/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap index ee65360e55b..5ab6de9a433 100644 --- a/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap +++ b/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap @@ -134,7 +134,6 @@ exports[`EuiQuickSelectPanels customQuickSelectPanels should render custom panel > = ( inputRef, readOnly, controlOnly, - onKeyDown: _onKeyDown, + onKeyUp: _onKeyUp, ...rest } = props; @@ -111,21 +109,22 @@ export const EuiFieldNumber: FunctionComponent = ( // will set :invalid state automatically, but we need to also set // `aria-invalid` as well as display an icon. We also want to *not* set this on // EuiValidatableControl, in order to not override custom validity messages - const [isNativelyInvalid, setIsNativelyInvalid] = useState(false); - const validityRef = useRef(null); - const setRefs = useCombinedRefs([validityRef, inputRef]); + const [isNativelyInvalid, setIsNativelyInvalid] = useState< + true | undefined + >(); // Note that we can't use hook into `onChange` because browsers don't emit change events // for invalid values - see https://github.com/facebook/react/issues/16554 - const onKeyDown = useCallback( + const onKeyUp = useCallback( (e: React.KeyboardEvent) => { - _onKeyDown?.(e); - // Wait a beat before checking validity - we can't use `e.target` as it's stale - requestAnimationFrame(() => { - setIsNativelyInvalid(!validityRef.current!.validity.valid); - }); + _onKeyUp?.(e); + + const { validity } = e.target as HTMLInputElement; + // Prefer `undefined` over `false` so that the `aria-invalid` prop unsets completely + const isInvalid = !validity.valid || undefined; + setIsNativelyInvalid(isInvalid); }, - [_onKeyDown] + [_onKeyUp] ); const numIconsClass = controlOnly @@ -155,9 +154,9 @@ export const EuiFieldNumber: FunctionComponent = ( placeholder={placeholder} readOnly={readOnly} className={classes} - ref={setRefs} - onKeyDown={onKeyDown} - aria-invalid={isInvalid || isNativelyInvalid} + ref={inputRef} + onKeyUp={onKeyUp} + aria-invalid={isInvalid == null ? isNativelyInvalid : isInvalid} {...rest} /> diff --git a/src/components/form/range/__snapshots__/dual_range.test.tsx.snap b/src/components/form/range/__snapshots__/dual_range.test.tsx.snap index db1152e1a6b..5515fd4f6f7 100644 --- a/src/components/form/range/__snapshots__/dual_range.test.tsx.snap +++ b/src/components/form/range/__snapshots__/dual_range.test.tsx.snap @@ -63,7 +63,6 @@ exports[`EuiDualRange input props can be applied to min and max inputs 1`] = ` class="euiFormControlLayout__childrenWrapper" >