-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: prevent focusout when closing date-picker on outside click (#7855…
…) (#7863) Co-authored-by: Serhii Kulykov <[email protected]>
- Loading branch information
1 parent
4da3920
commit e6de490
Showing
5 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/date-picker/src/vaadin-date-picker-overlay-mixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2015 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js'; | ||
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js'; | ||
import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js'; | ||
|
||
/** | ||
* @polymerMixin | ||
* @mixes OverlayMixin | ||
* @mixes PositionMixin | ||
*/ | ||
export const DatePickerOverlayMixin = (superClass) => | ||
class DatePickerOverlayMixin extends PositionMixin(OverlayMixin(superClass)) { | ||
/** | ||
* Override method inherited from `OverlayMixin` to not close on input click. | ||
* Needed to ignore date-picker's own input in the mousedown listener below. | ||
* | ||
* @param {Event} event | ||
* @return {boolean} | ||
* @protected | ||
*/ | ||
_shouldCloseOnOutsideClick(event) { | ||
const eventPath = event.composedPath(); | ||
return !eventPath.includes(this.positionTarget); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @override | ||
*/ | ||
_mouseDownListener(event) { | ||
super._mouseDownListener(event); | ||
|
||
// Prevent global mousedown event to avoid losing focus on outside click, | ||
// unless the clicked element is also focusable (e.g. in date-time-picker). | ||
if (this._shouldCloseOnOutsideClick(event) && !isElementFocusable(event.composedPath()[0])) { | ||
event.preventDefault(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters