Skip to content

fix(simple-single-select): clear selected option on ESC when option m…#1723

Merged
kabaros merged 3 commits intodhis2:masterfrom
CelsoDeCarvalho:LIBS-821/simple-single-select-clear-on-esc
Jan 30, 2026
Merged

fix(simple-single-select): clear selected option on ESC when option m…#1723
kabaros merged 3 commits intodhis2:masterfrom
CelsoDeCarvalho:LIBS-821/simple-single-select-clear-on-esc

Conversation

@CelsoDeCarvalho
Copy link
Contributor

@CelsoDeCarvalho CelsoDeCarvalho commented Jan 29, 2026

…enu is closed

Implements LIBS-821


Description

When the select is clearable, pressing ESC a second time now clears
the value if the popup is already dismissed, matching APG combobox
accessibility guidelines.


Known issues

  • issue

Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

All points above should be relevant for feature PRs. For bugfixes, some points might not be relevant. In that case, just check them anyway to signal the work is done.


Screenshots

supporting text

@CelsoDeCarvalho CelsoDeCarvalho requested a review from a team as a code owner January 29, 2026 10:38
Copy link
Collaborator

@kabaros kabaros left a comment

Choose a reason for hiding this comment

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

looking great, Celso - just a couple of small comments

}

if (!expanded && clearable && key === 'Escape') {
onClear()
Copy link
Collaborator

Choose a reason for hiding this comment

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

change this please to be more defensive, in case the consumer didn't pass the method

Suggested change
onClear()
onClear?.()

warning = false,
onBlur = () => undefined,
onClear = () => undefined,
onClear,
Copy link
Collaborator

Choose a reason for hiding this comment

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

leave the default param here - just in case there are other places that are not being defensive / checking the value of onClear

value: '',
})}
selected={selected}
setSelectedValue={setSelected}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you don't need to pass setSelectedValue anymore .. it's not used in the component

Suggested change
setSelectedValue={setSelected}

expect(onChange).toHaveBeenCalledWith({ value: 'foo', label: 'Foo' })
})

it('should clear the selected value when closed, clearable and user presses Escape', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

as discussed on Slack - adding a second test for when it's open initially would be good

@sonarqubecloud
Copy link

@kabaros kabaros merged commit 65299b1 into dhis2:master Jan 30, 2026
17 of 18 checks passed
@kabaros
Copy link
Collaborator

kabaros commented Jan 30, 2026

Great one Celso, thank you! 👏🏿

dhis2-bot added a commit that referenced this pull request Jan 30, 2026
## [10.12.6](v10.12.5...v10.12.6) (2026-01-30)

### Bug Fixes

* **simple-single-select:** clear selected option on ESC ([#1723](#1723)) ([65299b1](65299b1))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 10.12.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants