-
Notifications
You must be signed in to change notification settings - Fork 85
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: restore focus-ring when closing on click #4341
Conversation
this._overlayContent.addEventListener('focusin', () => { | ||
this._setFocused(true); | ||
if (this._keyboardActive) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is needed to avoid focus-ring
from getting removed on date click. Currently, it happens because FocusMixin
is also used in vaadin-month-calendar
which resets keyboardActive
flag.
if (this._openedWithFocusRing && this.hasAttribute('focused')) { | ||
this.setAttribute('focus-ring', ''); | ||
} else if (!this.hasAttribute('focused')) { | ||
this.blur(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is removed without replacement because it wasn't working anyways (focus is restored after a timeout). Furthermore, the case of calling input.blur()
is covered by focus
listener:
web-components/packages/date-picker/src/vaadin-date-picker-mixin.js
Lines 366 to 371 in 9e022ac
_onFocus(event) { | |
super._onFocus(event); | |
if (this._noInput) { | |
event.target.blur(); | |
} |
Kudos, SonarCloud Quality Gate passed!
|
This ticket/PR has been released with Vaadin 23.2.0.beta2 and is also targeting the upcoming stable 23.2.0 version. |
Description
Fixes #4154
TL;DR: after
focus-ring
is set after focusing with keyboard, only remove it on blur when the overlay is closed.Problem
Currently, the logic for restoring
focus-ring
in the date-picker is broken. The following happens when closing on click:<body>
(in case of outside click) or<td>
inside of<vaadin-month-calendar>
(cell click),focusout
event is fired on the<input>
and_setFocused(false)
removes thefocus-ring
attribute,focus-ring
is called too early, as the focus hasn't been restored to the<input>
yet,vaadin-overlay
restores focus, but notfocus-ring
because thekeyboardActive
isfalse
.Solution
Here is how this behavior will be changed after this PR is merged.
focusin
event, calling_setFocused(true)
sets the flag to indicate iffocus-ring
should be preserved,focusout
event,_setFocused(false)
is no longer called when opened (the focus will be restored anyways),focusin
after restoring focus back to the<input>
, there is no extra_setFocused(true)
call.keyboardActive
isfalse
when restoring focus, it's not checked andfocus-ring
is preserved.Type of change