Skip to content

Commit

Permalink
[EuiSearchBox][React@18 Legacy Mode] useLayoutEffect in search_box (
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant authored Sep 26, 2024
1 parent 780048c commit 84a92d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/eui/changelogs/upcoming/8047.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Bug fixes**

- Fixed `EuiSearchBox` skips input when running with React 18 in Legacy Mode

5 changes: 2 additions & 3 deletions packages/eui/src/components/search_bar/search_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* Side Public License, v 1.
*/

import React, { FunctionComponent, useRef } from 'react';
import React, { FunctionComponent, useRef, useLayoutEffect } from 'react';

import { useUpdateEffect } from '../../services';
import { useEuiI18n } from '../i18n';
import { EuiFieldSearch, EuiFieldSearchProps } from '../form';
import { EuiInputPopover } from '../popover';
Expand Down Expand Up @@ -39,7 +38,7 @@ export const EuiSearchBox: FunctionComponent<EuiSearchBoxProps> = ({
}) => {
const inputRef = useRef<HTMLInputElement | null>(null);

useUpdateEffect(() => {
useLayoutEffect(() => {
if (inputRef.current) {
inputRef.current.value = query;
inputRef.current.dispatchEvent(new Event('change'));
Expand Down

0 comments on commit 84a92d0

Please sign in to comment.