Skip to content

Commit ad2544e

Browse files
authored
[EuiComboBox] Fix new input size util not resetting correctly (#7240)
1 parent 01f23ab commit ad2544e

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/components/combo_box/combo_box.spec.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ describe('EuiComboBox', () => {
6868
);
6969
});
7070

71+
it('correctly resets the input size when the search value is cleared', () => {
72+
cy.realMount(<EuiComboBox options={[{ label: 'Test 1 2 3' }]} />);
73+
cy.get('[data-test-subj="comboBoxSearchInput"]').realClick();
74+
75+
cy.realType('Test 1 2 3');
76+
cy.get('[data-test-subj="comboBoxSearchInput"]').should(
77+
'have.attr',
78+
'style',
79+
'inline-size: 67px;'
80+
);
81+
82+
cy.realPress('{downarrow}');
83+
cy.realPress('Enter');
84+
cy.get('[data-test-subj="comboBoxSearchInput"]').should(
85+
'have.attr',
86+
'style',
87+
'inline-size: 2px;'
88+
);
89+
});
90+
7191
it('does not exceed the maximum possible width of the input wrapper', () => {
7292
cy.realMount(<EuiComboBox options={[]} />);
7393
cy.get('[data-test-subj="comboBoxSearchInput"]').realClick();

src/components/combo_box/combo_box_input/combo_box_input.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import React, {
1010
Component,
11-
ChangeEventHandler,
1211
FocusEventHandler,
1312
KeyboardEventHandler,
1413
RefCallback,
@@ -44,9 +43,9 @@ export interface EuiComboBoxInputProps<T> extends CommonProps {
4443
isListOpen: boolean;
4544
noIcon: boolean;
4645
onBlur?: FocusEventHandler<HTMLInputElement>;
47-
onChange?: (searchValue: string) => void;
46+
onChange: (searchValue: string) => void;
4847
onClear?: () => void;
49-
onClick?: () => void;
48+
onClick: () => void;
5049
onCloseListClick: () => void;
5150
onFocus: FocusEventHandler<HTMLInputElement>;
5251
onOpenListClick: () => void;
@@ -147,22 +146,15 @@ export class EuiComboBoxInput<T> extends Component<
147146
};
148147

149148
componentDidUpdate(prevProps: EuiComboBoxInputProps<T>) {
150-
const { searchValue } = prevProps;
149+
if (prevProps.searchValue !== this.props.searchValue) {
150+
this.updateInputSize(this.props.searchValue);
151151

152-
// We need to update the position of everything if the user enters enough input to change
153-
// the size of the input.
154-
if (searchValue !== this.props.searchValue) {
152+
// We need to update the position of everything if the user enters enough input to change
153+
// the size of the input.
155154
this.updatePosition();
156155
}
157156
}
158157

159-
inputOnChange: ChangeEventHandler<HTMLInputElement> = (event) => {
160-
const { value } = event.target;
161-
162-
this.updateInputSize(value);
163-
this.props.onChange?.(value);
164-
};
165-
166158
render() {
167159
const {
168160
compressed,
@@ -173,6 +165,7 @@ export class EuiComboBoxInput<T> extends Component<
173165
isDisabled,
174166
isListOpen,
175167
noIcon,
168+
onChange,
176169
onClear,
177170
onClick,
178171
onCloseListClick,
@@ -350,7 +343,7 @@ export class EuiComboBoxInput<T> extends Component<
350343
disabled={isDisabled}
351344
id={id}
352345
onBlur={this.onBlur}
353-
onChange={this.inputOnChange}
346+
onChange={(event) => onChange(event.target.value)}
354347
onFocus={this.onFocus}
355348
onKeyDown={this.onKeyDown}
356349
ref={this.inputRefCallback}

upcoming_changelogs/7240.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**Bug fixes**
2+
3+
- Fixed `EuiComboBox` search input width not resetting correctly on selection

0 commit comments

Comments
 (0)