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

fix(dropdown): close dropdown menu on Enter / Space #3180

Merged

Conversation

maxokorokov
Copy link
Member

Fixes #3142

@codecov-io
Copy link

codecov-io commented May 7, 2019

Codecov Report

Merging #3180 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3180      +/-   ##
==========================================
+ Coverage    91.9%   91.91%   +0.01%     
==========================================
  Files          91       91              
  Lines        3025     3030       +5     
  Branches      497      499       +2     
==========================================
+ Hits         2780     2785       +5     
  Misses        179      179              
  Partials       66       66
Flag Coverage Δ
#e2e 61.48% <100%> (+0.06%) ⬆️
#unit 89.32% <0%> (-0.15%) ⬇️
Impacted Files Coverage Δ
src/dropdown/dropdown.ts 94.37% <100%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bb6ddd...b6a7ee9. Read the comment docs.

'(keydown.End)': 'dropdown.onKeyDown($event)'
'(keydown.End)': 'dropdown.onKeyDown($event)',
'(keydown.Enter)': 'dropdown.onKeyDown($event)',
'(keydown.Space)': 'dropdown.onKeyDown($event)'
Copy link
Member

Choose a reason for hiding this comment

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

I think it's time to keep a single (keydown) binding and create a switch or []. includes in a local onKeyDown($event) that will delegate to dropdown.onKeyDown($event)

WDYT ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@benouat, I agreed and I have a refactoring of keyboard handling in works. Would ideally just keep it separate from this PR

  • you'll see a comment by @fbasso soon, but actually NgbDropdownToggle doesn't need (keydown.Enter|Space) handlers at all. I'll fix that in a bit.
  • I'll split the onKeyDown into two functions for NgbDropdownToggle and NgbDropdownMenu I guess and it should simplify things.

P.S. also [].includes needs a polyfill :)

Copy link
Member

@fbasso fbasso left a comment

Choose a reason for hiding this comment

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

Regarding the tests, we check that the dropdown has been closed on enter/space in some use-cases.

On the test 'should't close when clicking on the form input', we can check that the dropdown is not closed on enter/space.

@@ -109,7 +111,9 @@ export class NgbDropdownAnchor {
'(keydown.ArrowUp)': 'dropdown.onKeyDown($event)',
'(keydown.ArrowDown)': 'dropdown.onKeyDown($event)',
'(keydown.Home)': 'dropdown.onKeyDown($event)',
'(keydown.End)': 'dropdown.onKeyDown($event)'
'(keydown.End)': 'dropdown.onKeyDown($event)',
Copy link
Member

Choose a reason for hiding this comment

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

Handle this on the dropdown toggle doesn't seem to be necessary, as enter and space trigger the click (from Bootstrap specs, the toogle element is a button or a link only).

@maxokorokov maxokorokov force-pushed the dropdown/fix/close-on-enter-esc branch from 78da8cf to b6a7ee9 Compare May 13, 2019 13:09
@maxokorokov
Copy link
Member Author

maxokorokov commented May 13, 2019

@fbasso thanks for the review:

@maxokorokov maxokorokov merged commit 5163d03 into ng-bootstrap:master May 13, 2019
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.

Dropdown menu isn't closed on Enter / Space
4 participants