Skip to content

Commit

Permalink
fix(ComboBox): bring IME support back
Browse files Browse the repository at this point in the history
This change backs out carbon-design-system#3646 partially given moving `inputValue` state
syncing code from `handleOnInputValueChange` to `handleOnStateChange`
seems to break IME presumably because the different rendering timing
the change causes in-composition string (of IME) overriden by an older
value.
  • Loading branch information
asudoh committed Jan 6, 2020
1 parent 88c97e3 commit a32e9d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
8 changes: 2 additions & 6 deletions packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ describe('ComboBox', () => {
it('should set `inputValue` to an empty string if a falsey-y value is given', () => {
const wrapper = mount(<ComboBox {...mockProps} />);

wrapper
.instance()
.handleOnStateChange({ inputValue: 'foo' }, downshiftActions);
wrapper.instance().handleOnInputValueChange('foo', downshiftActions);
expect(wrapper.state('inputValue')).toBe('foo');

wrapper
.instance()
.handleOnStateChange({ inputValue: null }, downshiftActions);
wrapper.instance().handleOnInputValueChange(null, downshiftActions);
expect(wrapper.state('inputValue')).toBe('');
});
});
Expand Down
31 changes: 17 additions & 14 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,26 @@ export default class ComboBox extends React.Component {
}
};

handleOnInputValueChange = inputValue => {
const { onInputChange } = this.props;

this.setState(
() => ({
// Default to empty string if we have a false-y `inputValue`
inputValue: inputValue || '',
}),
() => {
if (onInputChange) {
onInputChange(inputValue);
}
}
);
};

handleOnStateChange = (newState, { setHighlightedIndex }) => {
if (Object.prototype.hasOwnProperty.call(newState, 'inputValue')) {
const { inputValue } = newState;
const { onInputChange } = this.props;

setHighlightedIndex(findHighlightedIndex(this.props, inputValue));

this.setState(
() => ({
// Default to empty string if we have a false-y `inputValue`
inputValue: inputValue || '',
}),
() => {
if (onInputChange) {
onInputChange(inputValue);
}
}
);
}
};

Expand Down Expand Up @@ -301,6 +303,7 @@ export default class ComboBox extends React.Component {
<Downshift
{...downshiftProps}
onChange={this.handleOnChange}
onInputValueChange={this.handleOnInputValueChange}
onStateChange={this.handleOnStateChange}
inputValue={this.state.inputValue || ''}
itemToString={itemToString}
Expand Down

0 comments on commit a32e9d7

Please sign in to comment.