Skip to content

Commit 6ef48b4

Browse files
committed
fix: use event.currentTarget instead of event.target
1 parent 0bab8a1 commit 6ef48b4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/components/datagrid/controls/display_selector.test.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import React from 'react';
10-
import { act } from 'react-dom/test-utils';
10+
import { act } from '@testing-library/react';
1111
import { shallow, mount, ShallowWrapper, ReactWrapper } from 'enzyme';
1212
import { testCustomHook } from '../../../test/internal';
1313

@@ -310,10 +310,19 @@ describe('useDataGridDisplaySelector', () => {
310310
component
311311
.find('input[type="range"][data-test-subj="lineCountNumber"]')
312312
.prop('value');
313-
const setLineCountNumber = (component: ReactWrapper, number: number) =>
314-
component
315-
.find('input[type="range"][data-test-subj="lineCountNumber"]')
316-
.simulate('change', { target: { value: number } });
313+
const setLineCountNumber = (
314+
component: ReactWrapper,
315+
number: number
316+
) => {
317+
const input = component.find(
318+
'input[type="range"][data-test-subj="lineCountNumber"]'
319+
);
320+
321+
// enzyme simulate() doesn't handle event.currentTarget updates well
322+
// https://github.com/enzymejs/enzyme/issues/218
323+
(input.getDOMNode() as HTMLInputElement).value = number.toString();
324+
input.simulate('change');
325+
};
317326

318327
it('conditionally displays a line count number input when the lineCount button is selected', () => {
319328
const component = mount(<MockComponent />);
@@ -357,7 +366,11 @@ describe('useDataGridDisplaySelector', () => {
357366
);
358367
openPopover(component);
359368

360-
setLineCountNumber(component, 3);
369+
act(() => {
370+
setLineCountNumber(component, 3);
371+
});
372+
component.update();
373+
361374
expect(getLineCountNumber(component)).toEqual(3);
362375
});
363376

src/components/datagrid/controls/display_selector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export const useDataGridDisplaySelector = (
140140
const setLineCountHeight = useCallback<
141141
NonNullable<EuiRangeProps['onChange']>
142142
>((event) => {
143-
if (!event.target) return;
143+
if (!event.currentTarget) return;
144144

145-
const newLineCount = Number((event.target as HTMLInputElement).value);
145+
const newLineCount = Number(event.currentTarget.value);
146146
if (newLineCount < 1) return; // Don't let users set a 0 or negative line count
147147

148148
setLineCount(newLineCount);

0 commit comments

Comments
 (0)