Skip to content

Commit 208b739

Browse files
Merge branch 'main' into fix/eui-plus-missing-content
2 parents 5b34e63 + 0e31d35 commit 208b739

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Updated `EuiInlineEditForm`'s `onCancel` prop type to allow uncontrolled mode usage
2+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**Bug fixes**
2+
3+
- Fixed a bug on `EuiSuperDatePicker` where pasting an absolute date would append the date instead of replace it
4+

packages/eui/src/components/date_picker/super_date_picker/date_popover/absolute_tab.test.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*/
88

99
import React from 'react';
10-
import { fireEvent } from '@testing-library/react';
10+
import { fireEvent, waitFor } from '@testing-library/react';
1111
import { render } from '../../../../test/rtl';
1212

1313
import { EuiAbsoluteTab } from './absolute_tab';
1414
import { LocaleSpecifier } from 'moment';
15+
import { userEvent } from '@storybook/test';
1516

1617
// Mock EuiDatePicker - 3rd party datepicker lib causes render issues
1718
jest.mock('../../date_picker', () => ({
@@ -69,7 +70,7 @@ describe('EuiAbsoluteTab', () => {
6970
expect(queryByText(formatHelpText)).toHaveClass('euiFormErrorText');
7071
});
7172

72-
it('immediately parses pasted text without needing an extra click or keypress', () => {
73+
it('immediately parses pasted text without needing an extra click or keypress', async () => {
7374
const { getByTestSubject, queryByText } = render(
7475
<EuiAbsoluteTab {...props} />
7576
);
@@ -80,9 +81,21 @@ describe('EuiAbsoluteTab', () => {
8081
fireEvent.paste(input, {
8182
clipboardData: { getData: () => '1970-01-01' },
8283
});
84+
8385
expect(input).not.toBeInvalid();
8486
expect(input.value).toContain('Jan 1, 1970');
8587

88+
// Additional pasting check as userEvent.paste more accurately simulates
89+
// the pasting behavior with side effects
90+
await waitFor(() => {
91+
input.focus();
92+
userEvent.paste('1970-01-02');
93+
});
94+
95+
// ensure value is replaced, not appended
96+
expect(input.value).not.toEqual('Jan 1, 1970 @ 00:00:00.0001970-01-02');
97+
expect(input.value).toEqual('Jan 2, 1970 @ 00:00:00.000');
98+
8699
input.value = '';
87100
fireEvent.paste(input, {
88101
clipboardData: { getData: () => 'not a date' },

packages/eui/src/components/date_picker/super_date_picker/date_popover/absolute_tab.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
188188
value={textInputValue}
189189
onChange={handleTextChange}
190190
onPaste={(event) => {
191+
// preventing default here ensures no additional onChange is
192+
// triggered which otherwise results in input duplication
193+
event.preventDefault();
194+
191195
setTextInputValue(event.clipboardData.getData('text'));
192196
setIsReadyToParse(true);
193197
}}

packages/eui/src/components/inline_edit/inline_edit_form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export type EuiInlineEditCommonProps = Omit<
9696
* Initial inline edit text value
9797
*/
9898
defaultValue: string;
99+
onCancel?: (previousValue: string) => void;
99100
},
100101
{
101102
/**
@@ -109,7 +110,7 @@ export type EuiInlineEditCommonProps = Omit<
109110
/**
110111
* Callback required to reset `value` to the previous read mode text value.
111112
*/
112-
onCancel: (perviousValue: string) => void;
113+
onCancel: (previousValue: string) => void;
113114
}
114115
>;
115116

0 commit comments

Comments
 (0)