Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(Dropdown): inserting char at a cursor position will the cursor to end #897

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update cached `rem` size value of `pxToRem` on theme static styles render @kuzhelov ([#883](https://github.com/stardust-ui/react/pull/883))
- Stardust in TS project with `--isolatedModules` can be built @layershifter ([#894](https://github.com/stardust-ui/react/pull/894))
- Keyframes are behaving as expected when RTL is dynamically switched @layershifter ([#894](https://github.com/stardust-ui/react/pull/894))
- Fix inserting char at a cursor position will the cursor to end in `Dropdown` @layershifter ([#897](https://github.com/stardust-ui/react/pull/897))

<!--------------------------------[ v0.21.0 ]------------------------------- -->
## [v0.21.0](https://github.com/stardust-ui/react/tree/v0.21.0) (2019-02-12)
Expand Down
22 changes: 11 additions & 11 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
<ElementType className={classes.root} {...unhandledProps}>
<Downshift
onChange={this.handleSelectedChange}
onInputValueChange={this.handleSearchQueryChange}
inputValue={search ? searchQuery : null}
stateReducer={this.handleDownshiftStateChanges}
itemToString={itemToString}
Expand Down Expand Up @@ -574,22 +575,21 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
)
}

private handleSearchQueryChange = (searchQuery: string) => {
this.trySetState({ searchQuery })
_.invoke(
this.props,
'onSearchQueryChange',
{}, // we don't have event for it, but want to keep the event handling interface, event is empty.
{ ...this.props, searchQuery },
)
}

private handleDownshiftStateChanges = (
state: DownshiftState<ShorthandValue>,
changes: StateChangeOptions<ShorthandValue>,
) => {
switch (changes.type) {
case Downshift.stateChangeTypes.changeInput:
this.trySetState({
searchQuery: changes.inputValue,
})
_.invoke(
this.props,
'onSearchQueryChange',
{}, // we don't have event for it, but want to keep the event handling interface, event is empty.
{ ...this.props, searchQuery: changes.inputValue },
)
return changes
case Downshift.stateChangeTypes.blurButton:
// Downshift closes the list by default on trigger blur. It does not support the case when dropdown is
// single selection and focuses list on trigger click/up/down/space/enter. Treating that here.
Expand Down