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(datepicker): refine focus state checks #3530

Closed

Conversation

peterblazejewicz
Copy link
Contributor

@peterblazejewicz peterblazejewicz commented Jan 6, 2020

This adds additional condition to restrict focus in/out to instance of
the datepicker by verifyng if focus event target and related targets are
descendants of the datepicker element. This removes false results based
only on the class name checks, which fail when focus is switched between
datepicker instances.

Closes #3494

/cc
@gpolychronisamadeus

  • read and followed the CONTRIBUTING.md guide.
  • built and tested the changes locally.

This adds additional condition to restrict focus in/out to instance of
the datepicker by verifyng if focus event target and related targets are
descendants of the datepicker element. This removes false results based
only on the class name checks, which fail when focus is switched between
datepicker instances.

Closes ng-bootstrap#3494
@codecov-io
Copy link

Codecov Report

Merging #3530 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3530   +/-   ##
=======================================
  Coverage   91.39%   91.39%           
=======================================
  Files          96       96           
  Lines        2800     2800           
  Branches      517      517           
=======================================
  Hits         2559     2559           
  Misses        183      183           
  Partials       58       58
Flag Coverage Δ
#e2e 56.46% <100%> (ø) ⬆️
#unit 88.24% <100%> (ø) ⬆️
Impacted Files Coverage Δ
src/datepicker/datepicker.ts 97.87% <100%> (ø) ⬆️

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 736953a...2a90c88. Read the comment docs.

Copy link
Member

@benouat benouat left a comment

Choose a reason for hiding this comment

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

Thanks @peterblazejewicz for the fix proposal. Seems that it should be fine!
Nonetheless, could you:

  • create a 💪 end2end test for that
  • make sure that there's no performance penalty overall by profiling before/after

Comment on lines +392 to +393
this._elementRef.nativeElement.contains(target as Node) &&
this._elementRef.nativeElement.contains(relatedTarget as Node))),
Copy link
Member

Choose a reason for hiding this comment

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

Please create a local reference const {nativeElement} = this._elementRef; outside of the Observable chain.

@maxokorokov
Copy link
Member

@peterblazejewicz or actually even a unit test might be fine, I think, if you simulate .click() between two datepicker dates and then press any arrow key. It will lose focus now.

@maxokorokov
Copy link
Member

Closing in favour of #3549 that is based on this commit + has tests

@maxokorokov maxokorokov closed this Feb 7, 2020
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.

bug(datepicker): Day focus doesn't work if more than 1 datepicker in same page
4 participants