UNPKG

1.09 kBJavaScriptView Raw
1import { MenuSurface } from '@material/mwc-menu/mwc-menu-surface.js';
2import { appDatePickerName } from '../date-picker/constants.js';
3import { appDatePickerInputName } from '../date-picker-input/constants.js';
4import { ElementMixin } from '../mixins/element-mixin.js';
5import { baseStyling, resetShadowRoot } from '../stylings.js';
6import { DatePickerInputSurfaceStyling } from './stylings.js';
7const alwaysOpenElementSet = new Set([
8 appDatePickerInputName,
9 appDatePickerName,
10]);
11export class DatePickerInputSurface extends ElementMixin(MenuSurface) {
12 static { this.styles = [
13 ...MenuSurface.styles,
14 baseStyling,
15 resetShadowRoot,
16 DatePickerInputSurfaceStyling,
17 ]; }
18 onBodyClick(ev) {
19 const elements = ev.composedPath()
20 .filter(({ nodeType }) => nodeType === Node.ELEMENT_NODE);
21 const shouldClose = elements.some(n => n.classList.contains('calendar-day') && !n.hasAttribute('aria-hidden')) ||
22 !elements.some(n => alwaysOpenElementSet.has(n.localName));
23 shouldClose && this.close();
24 }
25}