Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve UX of dropdown inputs #2774

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

ArtjomsPorss
Copy link
Contributor

@ArtjomsPorss ArtjomsPorss commented Oct 22, 2024

Description

Improves UX of inputs that use a dropdown. This includes:

  1. typing in the input and then clicking somewhere else(blur) does not delete the input contents anymore.
  2. to make typed text eligible for submission (in case of modal windows) it is required to select a dropdown option that corresponds to typed text.
  3. when item is selected in the dropdown, font becomes displayed in bold.
  4. changing text in the input after selecting option in the dropdown - deselects the dropdown option.

Changes cover:

  • Components that use InputDropdown component
  • Added Functional tests to cover these components
    • added data-wdio, data-testid attributes to html elements that are covered by functional tests
  • Refreshed snapshot tests
  • Fixed unit tests that started failing due to changes

Contribution Checklist:

  • The pull request does not introduce any breaking changes
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

{...(this.props.stateReducer !== undefined && {
stateReducer: (state, changes) => this.props.stateReducer(state, changes)
})}
defaultHighlightedIndex={0}
Copy link
Contributor Author

@ArtjomsPorss ArtjomsPorss Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first item in dropdown is highlighted by default allowing to select the item by pressing Enter on the keyboard

Comment on lines +354 to +361
stateReducer={(state, changes)=>{
// keep input changes when user clicks outside input
if(changes.type && (changes.type === Downshift.stateChangeTypes.mouseUp
|| changes.type === Downshift.stateChangeTypes.blurInput)) {
changes.inputValue = state.inputValue;
}
return changes;
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when input is defocused, input contents are not deleted anymore

@@ -345,16 +346,19 @@ class InputDropdown extends React.Component {
initialSelectedItem={defaultSelectedItem}
inputValue={this.props.value}
itemToString={this.props.itemToString}
onChange={(selected) => this.props.onChange(selected)}
onSelect={(selected) => this.props.onChange(selected)} // onSelect seem to trigger more consistently than onChange
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using onSelect instead of onChange because it triggered more consistently during functional tests

@@ -38,6 +39,7 @@ const Icon = (props) => {
onClick={props.onClick}
ref={props.innerRef}
data-testid='icon'
data-wdio={dataWdio}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for use in functional tests

@ArtjomsPorss ArtjomsPorss marked this pull request as ready for review October 22, 2024 16:32
@havetisyan havetisyan merged commit 3d07ae8 into AthenZ:master Oct 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants