@webtides/element-library 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/all.js +26 -0
- package/custom-elements.json +7683 -0
- package/index.js +3 -0
- package/package.json +132 -0
- package/patches/@glidejs+glide+3.6.2.patch +11 -0
- package/src/components/accordion/accordion.changelog.md +47 -0
- package/src/components/accordion/accordion.define.js +3 -0
- package/src/components/accordion/accordion.events.js +3 -0
- package/src/components/accordion/accordion.js +144 -0
- package/src/components/accordion/accordion.readme.md +71 -0
- package/src/components/accordion/accordion.style.js +64 -0
- package/src/components/accordion-group/accordion-group.changelog.md +35 -0
- package/src/components/accordion-group/accordion-group.define.js +3 -0
- package/src/components/accordion-group/accordion-group.js +63 -0
- package/src/components/accordion-group/accordion-group.readme.md +56 -0
- package/src/components/amount-field/amount-field.changelog.md +40 -0
- package/src/components/amount-field/amount-field.define.js +3 -0
- package/src/components/amount-field/amount-field.js +91 -0
- package/src/components/amount-field/amount-field.readme.md +65 -0
- package/src/components/amount-field/amount-field.style.js +58 -0
- package/src/components/button/button.changelog.md +19 -0
- package/src/components/button/button.define.js +3 -0
- package/src/components/button/button.js +174 -0
- package/src/components/button/button.readme.md +91 -0
- package/src/components/button/button.style.js +251 -0
- package/src/components/carousel/carousel.changelog.md +58 -0
- package/src/components/carousel/carousel.define.js +3 -0
- package/src/components/carousel/carousel.events.js +3 -0
- package/src/components/carousel/carousel.js +232 -0
- package/src/components/carousel/carousel.readme.md +78 -0
- package/src/components/carousel/carousel.style.js +142 -0
- package/src/components/carousel/glide/components/ShadowAnchors.js +12 -0
- package/src/components/carousel/glide/components/ShadowClones.js +41 -0
- package/src/components/carousel/glide/components/ShadowGaps.js +28 -0
- package/src/components/carousel/glide/components/ShadowHtml.js +32 -0
- package/src/components/checkbox-field/checkbox-field.changelog.md +47 -0
- package/src/components/checkbox-field/checkbox-field.define.js +3 -0
- package/src/components/checkbox-field/checkbox-field.js +102 -0
- package/src/components/checkbox-field/checkbox-field.readme.md +66 -0
- package/src/components/checkbox-field/checkbox-field.style.js +69 -0
- package/src/components/dialog/dialog.changelog.md +24 -0
- package/src/components/dialog/dialog.define.js +3 -0
- package/src/components/dialog/dialog.events.js +8 -0
- package/src/components/dialog/dialog.js +271 -0
- package/src/components/dialog/dialog.readme.md +122 -0
- package/src/components/dialog/dialog.style.js +124 -0
- package/src/components/dropdown/dropdown.changelog.md +39 -0
- package/src/components/dropdown/dropdown.define.js +3 -0
- package/src/components/dropdown/dropdown.js +98 -0
- package/src/components/dropdown/dropdown.readme.md +69 -0
- package/src/components/dropdown/dropdown.style.js +17 -0
- package/src/components/form-field/form-field.changelog.md +35 -0
- package/src/components/form-field/form-field.define.js +3 -0
- package/src/components/form-field/form-field.events.js +4 -0
- package/src/components/form-field/form-field.js +210 -0
- package/src/components/form-field/form-field.readme.md +80 -0
- package/src/components/form-field/form-field.style.js +25 -0
- package/src/components/input-field/input-field.changelog.md +39 -0
- package/src/components/input-field/input-field.define.js +3 -0
- package/src/components/input-field/input-field.js +71 -0
- package/src/components/input-field/input-field.readme.md +90 -0
- package/src/components/input-field/input-field.style.js +33 -0
- package/src/components/lazy-src/lazy-src.changelog.md +57 -0
- package/src/components/lazy-src/lazy-src.define.js +3 -0
- package/src/components/lazy-src/lazy-src.events.js +5 -0
- package/src/components/lazy-src/lazy-src.js +100 -0
- package/src/components/lazy-src/lazy-src.readme.md +63 -0
- package/src/components/notification/notification.changelog.md +22 -0
- package/src/components/notification/notification.define.js +3 -0
- package/src/components/notification/notification.events.js +6 -0
- package/src/components/notification/notification.js +280 -0
- package/src/components/notification/notification.readme.md +98 -0
- package/src/components/notification/notification.style.js +113 -0
- package/src/components/password-field/password-field.changelog.md +22 -0
- package/src/components/password-field/password-field.define.js +3 -0
- package/src/components/password-field/password-field.js +113 -0
- package/src/components/password-field/password-field.readme.md +60 -0
- package/src/components/password-field/password-field.style.js +62 -0
- package/src/components/radio-field/radio-field.changelog.md +21 -0
- package/src/components/radio-field/radio-field.define.js +3 -0
- package/src/components/radio-field/radio-field.js +140 -0
- package/src/components/radio-field/radio-field.readme.md +72 -0
- package/src/components/radio-field/radio-field.style.js +108 -0
- package/src/components/scroll-to/scroll-to.changelog.md +39 -0
- package/src/components/scroll-to/scroll-to.define.js +3 -0
- package/src/components/scroll-to/scroll-to.js +40 -0
- package/src/components/scroll-to/scroll-to.readme.md +50 -0
- package/src/components/scroll-to-top/scroll-to-top.changelog.md +39 -0
- package/src/components/scroll-to-top/scroll-to-top.define.js +3 -0
- package/src/components/scroll-to-top/scroll-to-top.js +78 -0
- package/src/components/scroll-to-top/scroll-to-top.readme.md +48 -0
- package/src/components/scroll-to-top/scroll-to-top.style.js +9 -0
- package/src/components/select-field/select-field.changelog.md +30 -0
- package/src/components/select-field/select-field.define.js +3 -0
- package/src/components/select-field/select-field.js +83 -0
- package/src/components/select-field/select-field.readme.md +131 -0
- package/src/components/select-field/select-field.style.js +24 -0
- package/src/components/slider/slider.changelog.md +177 -0
- package/src/components/slider/slider.define.js +3 -0
- package/src/components/slider/slider.events.js +4 -0
- package/src/components/slider/slider.js +338 -0
- package/src/components/slider/slider.readme.md +87 -0
- package/src/components/slider/slider.style.js +107 -0
- package/src/components/sticky/sticky.changelog.md +43 -0
- package/src/components/sticky/sticky.define.js +3 -0
- package/src/components/sticky/sticky.js +105 -0
- package/src/components/sticky/sticky.readme.md +63 -0
- package/src/components/sticky/sticky.style.js +21 -0
- package/src/components/svg-use/svg-use.changelog.md +41 -0
- package/src/components/svg-use/svg-use.define.js +3 -0
- package/src/components/svg-use/svg-use.js +39 -0
- package/src/components/svg-use/svg-use.readme.md +50 -0
- package/src/components/svg-use/svg-use.style.js +20 -0
- package/src/components/switch-field/switch-field.changelog.md +21 -0
- package/src/components/switch-field/switch-field.define.js +3 -0
- package/src/components/switch-field/switch-field.js +99 -0
- package/src/components/switch-field/switch-field.readme.md +58 -0
- package/src/components/switch-field/switch-field.style.js +98 -0
- package/src/components/tab-group/tab-group.changelog.md +35 -0
- package/src/components/tab-group/tab-group.define.js +3 -0
- package/src/components/tab-group/tab-group.js +109 -0
- package/src/components/tab-group/tab-group.readme.md +61 -0
- package/src/components/tab-group/tab-group.style.js +7 -0
- package/src/components/tab-link/tab-link.changelog.md +35 -0
- package/src/components/tab-link/tab-link.define.js +3 -0
- package/src/components/tab-link/tab-link.js +50 -0
- package/src/components/tab-link/tab-link.readme.md +66 -0
- package/src/components/tab-link/tab-link.style.js +32 -0
- package/src/components/tab-panel/tab-panel.changelog.md +39 -0
- package/src/components/tab-panel/tab-panel.define.js +3 -0
- package/src/components/tab-panel/tab-panel.js +30 -0
- package/src/components/tab-panel/tab-panel.readme.md +57 -0
- package/src/components/tab-panel/tab-panel.style.js +7 -0
- package/src/components/textarea-field/textarea-field.changelog.md +39 -0
- package/src/components/textarea-field/textarea-field.define.js +3 -0
- package/src/components/textarea-field/textarea-field.js +62 -0
- package/src/components/textarea-field/textarea-field.readme.md +102 -0
- package/src/components/textarea-field/textarea-field.style.js +7 -0
- package/src/components/transition-classes/transition-classes.changelog.md +39 -0
- package/src/components/transition-classes/transition-classes.define.js +3 -0
- package/src/components/transition-classes/transition-classes.js +154 -0
- package/src/components/transition-classes/transition-classes.readme.md +71 -0
- package/src/themes/default.css +165 -0
- package/src/themes/high-contrast.css +147 -0
- package/src/themes/sketchy.css +238 -0
- package/types/all.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/src/components/accordion/accordion.d.ts +60 -0
- package/types/src/components/accordion/accordion.define.d.ts +1 -0
- package/types/src/components/accordion/accordion.events.d.ts +4 -0
- package/types/src/components/accordion/accordion.style.d.ts +2 -0
- package/types/src/components/accordion-group/accordion-group.d.ts +28 -0
- package/types/src/components/accordion-group/accordion-group.define.d.ts +1 -0
- package/types/src/components/amount-field/amount-field.d.ts +53 -0
- package/types/src/components/amount-field/amount-field.define.d.ts +1 -0
- package/types/src/components/amount-field/amount-field.style.d.ts +2 -0
- package/types/src/components/button/button.d.ts +73 -0
- package/types/src/components/button/button.define.d.ts +1 -0
- package/types/src/components/button/button.style.d.ts +2 -0
- package/types/src/components/carousel/carousel.d.ts +79 -0
- package/types/src/components/carousel/carousel.define.d.ts +1 -0
- package/types/src/components/carousel/carousel.events.d.ts +4 -0
- package/types/src/components/carousel/carousel.style.d.ts +2 -0
- package/types/src/components/carousel/glide/components/ShadowAnchors.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowClones.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowGaps.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowHtml.d.ts +1 -0
- package/types/src/components/checkbox-field/checkbox-field.d.ts +69 -0
- package/types/src/components/checkbox-field/checkbox-field.define.d.ts +1 -0
- package/types/src/components/checkbox-field/checkbox-field.style.d.ts +2 -0
- package/types/src/components/dialog/dialog.d.ts +103 -0
- package/types/src/components/dialog/dialog.define.d.ts +1 -0
- package/types/src/components/dialog/dialog.events.d.ts +9 -0
- package/types/src/components/dialog/dialog.style.d.ts +2 -0
- package/types/src/components/dropdown/dropdown.d.ts +45 -0
- package/types/src/components/dropdown/dropdown.define.d.ts +1 -0
- package/types/src/components/dropdown/dropdown.style.d.ts +2 -0
- package/types/src/components/form-field/form-field.d.ts +110 -0
- package/types/src/components/form-field/form-field.define.d.ts +1 -0
- package/types/src/components/form-field/form-field.events.d.ts +5 -0
- package/types/src/components/form-field/form-field.style.d.ts +2 -0
- package/types/src/components/input-field/input-field.d.ts +38 -0
- package/types/src/components/input-field/input-field.define.d.ts +1 -0
- package/types/src/components/input-field/input-field.style.d.ts +2 -0
- package/types/src/components/lazy-src/lazy-src.d.ts +46 -0
- package/types/src/components/lazy-src/lazy-src.define.d.ts +1 -0
- package/types/src/components/lazy-src/lazy-src.events.d.ts +6 -0
- package/types/src/components/notification/notification.d.ts +92 -0
- package/types/src/components/notification/notification.define.d.ts +1 -0
- package/types/src/components/notification/notification.events.d.ts +7 -0
- package/types/src/components/notification/notification.style.d.ts +2 -0
- package/types/src/components/password-field/password-field.d.ts +66 -0
- package/types/src/components/password-field/password-field.define.d.ts +1 -0
- package/types/src/components/password-field/password-field.style.d.ts +2 -0
- package/types/src/components/radio-field/radio-field.d.ts +62 -0
- package/types/src/components/radio-field/radio-field.define.d.ts +1 -0
- package/types/src/components/radio-field/radio-field.style.d.ts +2 -0
- package/types/src/components/scroll-to/scroll-to.d.ts +24 -0
- package/types/src/components/scroll-to/scroll-to.define.d.ts +1 -0
- package/types/src/components/scroll-to-top/scroll-to-top.d.ts +32 -0
- package/types/src/components/scroll-to-top/scroll-to-top.define.d.ts +1 -0
- package/types/src/components/scroll-to-top/scroll-to-top.style.d.ts +2 -0
- package/types/src/components/select-field/select-field.d.ts +39 -0
- package/types/src/components/select-field/select-field.define.d.ts +1 -0
- package/types/src/components/select-field/select-field.style.d.ts +2 -0
- package/types/src/components/slider/slider.d.ts +129 -0
- package/types/src/components/slider/slider.define.d.ts +1 -0
- package/types/src/components/slider/slider.events.d.ts +5 -0
- package/types/src/components/slider/slider.style.d.ts +2 -0
- package/types/src/components/sticky/sticky.d.ts +47 -0
- package/types/src/components/sticky/sticky.define.d.ts +1 -0
- package/types/src/components/sticky/sticky.style.d.ts +2 -0
- package/types/src/components/svg-use/svg-use.d.ts +18 -0
- package/types/src/components/svg-use/svg-use.define.d.ts +1 -0
- package/types/src/components/svg-use/svg-use.style.d.ts +2 -0
- package/types/src/components/switch-field/switch-field.d.ts +67 -0
- package/types/src/components/switch-field/switch-field.define.d.ts +1 -0
- package/types/src/components/switch-field/switch-field.style.d.ts +2 -0
- package/types/src/components/tab-group/tab-group.d.ts +48 -0
- package/types/src/components/tab-group/tab-group.define.d.ts +1 -0
- package/types/src/components/tab-group/tab-group.style.d.ts +2 -0
- package/types/src/components/tab-link/tab-link.d.ts +30 -0
- package/types/src/components/tab-link/tab-link.define.d.ts +1 -0
- package/types/src/components/tab-link/tab-link.style.d.ts +2 -0
- package/types/src/components/tab-panel/tab-panel.d.ts +18 -0
- package/types/src/components/tab-panel/tab-panel.define.d.ts +1 -0
- package/types/src/components/tab-panel/tab-panel.style.d.ts +2 -0
- package/types/src/components/textarea-field/textarea-field.d.ts +34 -0
- package/types/src/components/textarea-field/textarea-field.define.d.ts +1 -0
- package/types/src/components/textarea-field/textarea-field.style.d.ts +2 -0
- package/types/src/components/transition-classes/transition-classes.d.ts +52 -0
- package/types/src/components/transition-classes/transition-classes.define.d.ts +1 -0
- package/types/src/utils/body-scroll.d.ts +4 -0
- package/types/src/utils/transitions.d.ts +9 -0
- package/web-types.json +3956 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { TemplateElement, html, defineElement, spreadAttributes } from '@webtides/element-js';
|
|
2
|
+
import style from './dialog.style.js';
|
|
3
|
+
import Events from './dialog.events.js';
|
|
4
|
+
import { lockBodyScroll, unlockBodyScroll } from '../../utils/body-scroll.js';
|
|
5
|
+
import { afterTransition, nextFrame } from '../../utils/transitions.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A modal dialog built on the native `<dialog>` element, so the platform owns focus trapping,
|
|
9
|
+
* background `inert`, top-layer rendering, focus restoration and `<form method="dialog">`
|
|
10
|
+
* auto-close. The component adds an animated, cancelable open/close lifecycle and ref-counted
|
|
11
|
+
* body-scroll locking on top. API modelled on Shoelace's `<sl-dialog>`.
|
|
12
|
+
*
|
|
13
|
+
* @element el-dialog
|
|
14
|
+
*
|
|
15
|
+
* @fires {CustomEvent} dialog-show - Fired when the dialog starts to open.
|
|
16
|
+
* @fires {CustomEvent} dialog-after-show - Fired once the open transition has finished.
|
|
17
|
+
* @fires {CustomEvent} dialog-hide - Fired when the dialog starts to close.
|
|
18
|
+
* @fires {CustomEvent} dialog-after-hide - Fired once the close transition has finished.
|
|
19
|
+
* @fires {CustomEvent} dialog-initial-focus - Fired after the dialog has been opened and the
|
|
20
|
+
* platform has moved focus inside it. Cancelable: call `preventDefault()` to take over focus.
|
|
21
|
+
* @fires {CustomEvent<{ source: 'close-button' | 'keyboard' | 'overlay' }>} dialog-request-close -
|
|
22
|
+
* Fired before the dialog closes in response to the close button, `Escape`, or an overlay
|
|
23
|
+
* click. Cancelable: call `preventDefault()` to keep the dialog open.
|
|
24
|
+
*
|
|
25
|
+
* @slot - The dialog's main content (body).
|
|
26
|
+
* @slot label - The dialog's title. Takes precedence over the `label` attribute.
|
|
27
|
+
* @slot header-actions - Optional controls rendered in the header, before the close button.
|
|
28
|
+
* @slot footer - Footer content, typically action buttons. The footer collapses when empty.
|
|
29
|
+
*
|
|
30
|
+
* @csspart base - The native `<dialog>` element — the panel surface (background, border, radius,
|
|
31
|
+
* elevation). The overlay is its `::backdrop` pseudo-element.
|
|
32
|
+
* @csspart header - The header row wrapping the title, header actions and close button.
|
|
33
|
+
* @csspart title - The title heading.
|
|
34
|
+
* @csspart header-actions - The container for the `header-actions` slot.
|
|
35
|
+
* @csspart close-button - The built-in close button.
|
|
36
|
+
* @csspart body - The scrollable body wrapping the default slot.
|
|
37
|
+
* @csspart footer - The footer wrapping the `footer` slot.
|
|
38
|
+
*
|
|
39
|
+
* @cssstate open - Set while the dialog is open. Style with `:host(:state(open))` or
|
|
40
|
+
* `el-dialog:state(open)` from outside.
|
|
41
|
+
*
|
|
42
|
+
* @property {boolean} open - Whether the dialog is open. Reflected to the `open` attribute.
|
|
43
|
+
* @property {string} label - The dialog's title (used when the `label` slot is empty); also the
|
|
44
|
+
* accessible name when `no-header` is set.
|
|
45
|
+
* @property {boolean} noHeader - Removes the header (title and built-in close button). Provide
|
|
46
|
+
* your own dismissal when set. Reflected to the `no-header` attribute.
|
|
47
|
+
* @property {string} closeLabel - Accessible label for the built-in close button. Default `'Close'`.
|
|
48
|
+
*/
|
|
49
|
+
export default class Dialog extends TemplateElement {
|
|
50
|
+
constructor() {
|
|
51
|
+
super({
|
|
52
|
+
shadowRender: true,
|
|
53
|
+
styles: [style],
|
|
54
|
+
propertyOptions: { open: { reflect: true }, noHeader: { reflect: true } },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
properties() {
|
|
59
|
+
return {
|
|
60
|
+
open: false,
|
|
61
|
+
label: '',
|
|
62
|
+
noHeader: false,
|
|
63
|
+
closeLabel: 'Close',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
connected() {
|
|
68
|
+
// The watcher does not run during initial hydration, so honour a declaratively-open dialog here.
|
|
69
|
+
if (this.open) {
|
|
70
|
+
this._internals.states.add('open');
|
|
71
|
+
this._applyOpen();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
disconnected() {
|
|
76
|
+
// Release the scroll lock we took if the dialog is torn down while open.
|
|
77
|
+
if (this.$refs.dialog?.open) {
|
|
78
|
+
unlockBodyScroll();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
watch() {
|
|
83
|
+
return {
|
|
84
|
+
open: (open) => {
|
|
85
|
+
if (open) {
|
|
86
|
+
this._internals.states.add('open');
|
|
87
|
+
this._applyOpen();
|
|
88
|
+
} else {
|
|
89
|
+
this._internals.states.delete('open');
|
|
90
|
+
this._applyClose();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
events() {
|
|
97
|
+
return {
|
|
98
|
+
'[data-dialog-close]': {
|
|
99
|
+
click: () => this.requestClose('close-button'),
|
|
100
|
+
},
|
|
101
|
+
"slot[name='footer']": {
|
|
102
|
+
slotchange: (event) => this._syncFooter(event.target),
|
|
103
|
+
},
|
|
104
|
+
"[part~='base']": {
|
|
105
|
+
// The UA fires `cancel` on Escape; route it through our cancelable close flow.
|
|
106
|
+
cancel: (event) => {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
this.requestClose('keyboard');
|
|
109
|
+
},
|
|
110
|
+
click: (event) => this._handleOverlayClick(event),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Opens the dialog.
|
|
117
|
+
* @returns {Promise<void>} Resolves after the open transition has finished.
|
|
118
|
+
*/
|
|
119
|
+
show() {
|
|
120
|
+
if (this.open) return Promise.resolve();
|
|
121
|
+
const done = this._once(Events.AFTER_SHOW);
|
|
122
|
+
this.open = true;
|
|
123
|
+
return done;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Closes the dialog.
|
|
128
|
+
* @returns {Promise<void>} Resolves after the close transition has finished.
|
|
129
|
+
*/
|
|
130
|
+
hide() {
|
|
131
|
+
if (!this.open) return Promise.resolve();
|
|
132
|
+
const done = this._once(Events.AFTER_HIDE);
|
|
133
|
+
this.open = false;
|
|
134
|
+
return done;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Requests that the dialog close, emitting the cancelable `dialog-request-close` event. When a
|
|
139
|
+
* listener calls `preventDefault()` the dialog stays open and plays a short deny animation.
|
|
140
|
+
* @param {'close-button' | 'keyboard' | 'overlay'} source - What triggered the request.
|
|
141
|
+
* @returns {void}
|
|
142
|
+
*/
|
|
143
|
+
requestClose(source) {
|
|
144
|
+
// element-js's dispatch() swallows the dispatchEvent() return value, so build the cancelable
|
|
145
|
+
// event by hand to read defaultPrevented.
|
|
146
|
+
const event = new CustomEvent(Events.REQUEST_CLOSE, {
|
|
147
|
+
bubbles: true,
|
|
148
|
+
composed: true,
|
|
149
|
+
cancelable: true,
|
|
150
|
+
detail: { source },
|
|
151
|
+
});
|
|
152
|
+
this.dispatchEvent(event);
|
|
153
|
+
|
|
154
|
+
if (event.defaultPrevented) {
|
|
155
|
+
this._denyClose();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.open = false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** @private */
|
|
162
|
+
async _applyOpen() {
|
|
163
|
+
const dialog = this.$refs.dialog;
|
|
164
|
+
if (!dialog || dialog.open) return;
|
|
165
|
+
|
|
166
|
+
this.dispatch(Events.SHOW);
|
|
167
|
+
lockBodyScroll();
|
|
168
|
+
dialog.showModal();
|
|
169
|
+
// The platform has now moved focus inside the dialog; let consumers redirect it.
|
|
170
|
+
this.dispatch(Events.INITIAL_FOCUS);
|
|
171
|
+
|
|
172
|
+
await nextFrame();
|
|
173
|
+
dialog.classList.add('showing');
|
|
174
|
+
await afterTransition(dialog);
|
|
175
|
+
this.dispatch(Events.AFTER_SHOW);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @private */
|
|
179
|
+
async _applyClose() {
|
|
180
|
+
const dialog = this.$refs.dialog;
|
|
181
|
+
if (!dialog || !dialog.open) return;
|
|
182
|
+
|
|
183
|
+
this.dispatch(Events.HIDE);
|
|
184
|
+
dialog.classList.remove('showing');
|
|
185
|
+
await afterTransition(dialog);
|
|
186
|
+
dialog.close();
|
|
187
|
+
unlockBodyScroll();
|
|
188
|
+
this.dispatch(Events.AFTER_HIDE);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** @private */
|
|
192
|
+
_handleOverlayClick(event) {
|
|
193
|
+
const dialog = this.$refs.dialog;
|
|
194
|
+
if (event.target !== dialog) return;
|
|
195
|
+
// A click whose target is the dialog itself is either the backdrop or the element's own
|
|
196
|
+
// padding. Treat it as an overlay click only when it lands outside the panel box.
|
|
197
|
+
const rect = dialog.getBoundingClientRect();
|
|
198
|
+
const inside =
|
|
199
|
+
event.clientX >= rect.left &&
|
|
200
|
+
event.clientX <= rect.right &&
|
|
201
|
+
event.clientY >= rect.top &&
|
|
202
|
+
event.clientY <= rect.bottom;
|
|
203
|
+
if (!inside) this.requestClose('overlay');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** @private */
|
|
207
|
+
_denyClose() {
|
|
208
|
+
const dialog = this.$refs.dialog;
|
|
209
|
+
if (!dialog?.animate) return;
|
|
210
|
+
if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches) return;
|
|
211
|
+
dialog.animate([{ transform: 'scale(1)' }, { transform: 'scale(1.02)' }, { transform: 'scale(1)' }], {
|
|
212
|
+
duration: 150,
|
|
213
|
+
easing: 'ease',
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @private */
|
|
218
|
+
_syncFooter(slot) {
|
|
219
|
+
const hasContent = slot
|
|
220
|
+
.assignedNodes({ flatten: true })
|
|
221
|
+
.some((node) => node.nodeType === Node.ELEMENT_NODE || node.textContent.trim() !== '');
|
|
222
|
+
this.$refs.footer?.classList.toggle('is-empty', !hasContent);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @private */
|
|
226
|
+
_once(name) {
|
|
227
|
+
return new Promise((resolve) => this.addEventListener(name, () => resolve(), { once: true }));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** @private */
|
|
231
|
+
headerTemplate() {
|
|
232
|
+
return html`
|
|
233
|
+
<div part="header">
|
|
234
|
+
<h2 part="title" id="title"><slot name="label">${this.label}</slot></h2>
|
|
235
|
+
<span part="header-actions"><slot name="header-actions"></slot></span>
|
|
236
|
+
<button part="close-button" type="button" aria-label="${this.closeLabel}" data-dialog-close>
|
|
237
|
+
<svg
|
|
238
|
+
viewBox="0 0 24 24"
|
|
239
|
+
fill="none"
|
|
240
|
+
stroke="currentColor"
|
|
241
|
+
stroke-width="2"
|
|
242
|
+
stroke-linecap="round"
|
|
243
|
+
stroke-linejoin="round"
|
|
244
|
+
aria-hidden="true"
|
|
245
|
+
>
|
|
246
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
247
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
248
|
+
</svg>
|
|
249
|
+
</button>
|
|
250
|
+
</div>
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
template() {
|
|
255
|
+
const labelling = this.noHeader ? { 'aria-label': this.label || undefined } : { 'aria-labelledby': 'title' };
|
|
256
|
+
|
|
257
|
+
return html`
|
|
258
|
+
<dialog ref="dialog" part="base" ${spreadAttributes(labelling)}>
|
|
259
|
+
${this.noHeader ? '' : this.headerTemplate()}
|
|
260
|
+
<div part="body"><slot></slot></div>
|
|
261
|
+
<div part="footer" ref="footer" class="is-empty"><slot name="footer"></slot></div>
|
|
262
|
+
</dialog>
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function define() {
|
|
268
|
+
defineElement('el-dialog', Dialog);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export { Events };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Dialog
|
|
2
|
+
|
|
3
|
+
`dialog` is a modal dialog built on the native `<dialog>` element. The platform handles focus trapping, making the background `inert`, top-layer rendering (no `z-index` juggling), focus restoration on close, and `<form method="dialog">` auto-close. On top of that the component adds an animated, cancelable open/close lifecycle and ref-counted body-scroll locking.
|
|
4
|
+
|
|
5
|
+
It is headless by default — without a theme it imposes no colors, borders, shadows or backdrop. Opt in by importing a theme (or setting the `--el-*` tokens yourself).
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
|
|
9
|
+
#### Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i --save @webtides/element-library
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Use
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import '@webtides/element-library/dialog/define';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<button type="button" onclick="document.querySelector('el-dialog').show()">Open</button>
|
|
23
|
+
|
|
24
|
+
<el-dialog label="Confirm">
|
|
25
|
+
<p>Are you sure you want to continue?</p>
|
|
26
|
+
<button slot="footer" type="button" onclick="this.closest('el-dialog').hide()">Cancel</button>
|
|
27
|
+
<button slot="footer" type="button" onclick="this.closest('el-dialog').hide()">OK</button>
|
|
28
|
+
</el-dialog>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Open and close it imperatively with the `show()` / `hide()` methods (both return a promise that resolves once the transition finishes), or by toggling the `open` attribute/property.
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
#### Properties/Attributes
|
|
36
|
+
|
|
37
|
+
| Name | Type | Default | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `open` | `boolean` | `false` | Whether the dialog is open. Reflected to the `open` attribute. |
|
|
40
|
+
| `label` | `string` | `''` | The dialog's title (used when the `label` slot is empty); the accessible name when headless. |
|
|
41
|
+
| `no-header` | `boolean` | `false` | Removes the header (title and built-in close button). Reflected to the `no-header` attribute. |
|
|
42
|
+
| `close-label` | `string` | `'Close'` | Accessible label for the built-in close button. |
|
|
43
|
+
|
|
44
|
+
#### Methods
|
|
45
|
+
|
|
46
|
+
| Name | Returns | Description |
|
|
47
|
+
| ---------------------- | --------------- | -------------------------------------------------------------- |
|
|
48
|
+
| `show()` | `Promise<void>` | Opens the dialog; resolves after the open transition. |
|
|
49
|
+
| `hide()` | `Promise<void>` | Closes the dialog; resolves after the close transition. |
|
|
50
|
+
| `requestClose(source)` | `void` | Requests a close, emitting the cancelable request-close event. |
|
|
51
|
+
|
|
52
|
+
#### Events
|
|
53
|
+
|
|
54
|
+
| Name | Cancelable | Detail | Description |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
56
|
+
| `dialog-show` | no | — | The dialog starts to open. |
|
|
57
|
+
| `dialog-after-show` | no | — | The open transition has finished. |
|
|
58
|
+
| `dialog-hide` | no | — | The dialog starts to close. |
|
|
59
|
+
| `dialog-after-hide` | no | — | The close transition has finished. |
|
|
60
|
+
| `dialog-initial-focus` | yes | — | Focus has moved into the dialog; prevent to override. |
|
|
61
|
+
| `dialog-request-close` | yes | `{ source: 'close-button' \| 'keyboard' \| 'overlay' }` | A close was requested; `preventDefault()` to keep open. |
|
|
62
|
+
|
|
63
|
+
#### Slots
|
|
64
|
+
|
|
65
|
+
| Name | Description |
|
|
66
|
+
| ---------------- | ---------------------------------------------------------------- |
|
|
67
|
+
| _(default)_ | The dialog's main content (body). |
|
|
68
|
+
| `label` | The dialog's title. Takes precedence over the `label` attribute. |
|
|
69
|
+
| `header-actions` | Optional controls in the header, before the close button. |
|
|
70
|
+
| `footer` | Footer content, typically action buttons. Collapses when empty. |
|
|
71
|
+
|
|
72
|
+
#### CSS Parts
|
|
73
|
+
|
|
74
|
+
| Name | Description |
|
|
75
|
+
| ---------------- | ---------------------------------------------------------------------------------- |
|
|
76
|
+
| `base` | The native `<dialog>` — the panel surface. The overlay is its `::backdrop` pseudo. |
|
|
77
|
+
| `header` | The header row (title, header actions, close button). |
|
|
78
|
+
| `title` | The title heading. |
|
|
79
|
+
| `header-actions` | The container for the `header-actions` slot. |
|
|
80
|
+
| `close-button` | The built-in close button. |
|
|
81
|
+
| `body` | The scrollable body wrapping the default slot. |
|
|
82
|
+
| `footer` | The footer wrapping the `footer` slot. |
|
|
83
|
+
|
|
84
|
+
#### CSS States
|
|
85
|
+
|
|
86
|
+
| Name | Description |
|
|
87
|
+
| ------ | --------------------------------------------------------------------------------- |
|
|
88
|
+
| `open` | Present on the host while the dialog is open. Style with `el-dialog:state(open)`. |
|
|
89
|
+
|
|
90
|
+
#### CSS Custom Properties
|
|
91
|
+
|
|
92
|
+
Headless by default; reads the library's `--el-*` design tokens (e.g. `--el-color-bg`, `--el-color-border`, `--el-radius-lg`, `--el-shadow-lg`, `--el-space-4`, `--el-duration-md`, `--el-ease`). Two dialog-specific tokens fine-tune the surface:
|
|
93
|
+
|
|
94
|
+
| Name | Default | Description |
|
|
95
|
+
| -------------------------------- | ------------- | ------------------------------------------- |
|
|
96
|
+
| `--el-dialog-width` | `31rem` | The dialog's width. |
|
|
97
|
+
| `--el-dialog-overlay-background` | `transparent` | The `::backdrop` background. |
|
|
98
|
+
| `--el-dialog-enter-offset` | `0.5rem` | Vertical offset the panel animates in from. |
|
|
99
|
+
|
|
100
|
+
See the Storybook _Docs / Theming_ page for the full token reference.
|
|
101
|
+
|
|
102
|
+
## Accessibility
|
|
103
|
+
|
|
104
|
+
- Opening calls `showModal()`, so focus is trapped, the rest of the page is `inert`, and focus is restored to the previously focused element on close.
|
|
105
|
+
- The dialog is labelled by its title; with `no-header`, set `label` to provide the accessible name.
|
|
106
|
+
- Initial focus honours the native `autofocus` attribute on a child. Listen for `dialog-initial-focus` and `preventDefault()` to manage focus yourself.
|
|
107
|
+
- `Escape` is routed through the cancelable `dialog-request-close` event so it can be blocked.
|
|
108
|
+
- Both shipped themes collapse the open/close transition under `prefers-reduced-motion: reduce`.
|
|
109
|
+
|
|
110
|
+
## Scroll locking
|
|
111
|
+
|
|
112
|
+
While a dialog is open, page scrolling is locked (ref-counted, so stacked dialogs cooperate). Hiding the scrollbar would normally widen the page and cause a layout shift, so the dialog pads the document by the removed scrollbar's width to keep the content steady. This is a no-op on overlay-scrollbar systems (e.g. macOS), where the scrollbar takes no layout space.
|
|
113
|
+
|
|
114
|
+
This compensation covers normal page content, but `position: fixed` elements pinned to the right edge (a floating action button, a sticky toolbar) are positioned against the viewport and still shift by the scrollbar width when it disappears. To avoid that entirely, reserve the scrollbar gutter on your document up front:
|
|
115
|
+
|
|
116
|
+
```css
|
|
117
|
+
:root {
|
|
118
|
+
scrollbar-gutter: stable;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
With the gutter always reserved, the scrollbar's space never changes between locked and unlocked, so neither the page nor fixed elements move.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const css = String.raw;
|
|
2
|
+
|
|
3
|
+
export default css`
|
|
4
|
+
:host {
|
|
5
|
+
display: contents;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* The native <dialog> is the top-layer surface (the "panel"). It is headless by default —
|
|
10
|
+
* every visual token falls back to a null-ish value so an unthemed dialog imposes nothing.
|
|
11
|
+
*/
|
|
12
|
+
dialog {
|
|
13
|
+
margin: auto;
|
|
14
|
+
padding: 0;
|
|
15
|
+
border: var(--el-border-width, 0) solid var(--el-color-border, transparent);
|
|
16
|
+
border-radius: var(--el-radius-lg, 0);
|
|
17
|
+
background: var(--el-color-bg, transparent);
|
|
18
|
+
color: var(--el-color-fg, inherit);
|
|
19
|
+
box-shadow: var(--el-shadow-lg, none);
|
|
20
|
+
|
|
21
|
+
width: var(--el-dialog-width, 31rem);
|
|
22
|
+
max-width: calc(100vw - 2 * var(--el-space-4, 1rem));
|
|
23
|
+
max-height: calc(100vh - 2 * var(--el-space-4, 1rem));
|
|
24
|
+
|
|
25
|
+
opacity: 0;
|
|
26
|
+
transform: translateY(var(--el-dialog-enter-offset, 0.5rem));
|
|
27
|
+
transition:
|
|
28
|
+
opacity var(--el-duration-md, 0s) var(--el-ease, ease),
|
|
29
|
+
transform var(--el-duration-md, 0s) var(--el-ease, ease);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Lay the box out only while open so the UA's \`dialog:not([open]) { display: none }\` still hides it. */
|
|
33
|
+
dialog[open] {
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
dialog.showing {
|
|
39
|
+
opacity: 1;
|
|
40
|
+
transform: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dialog::backdrop {
|
|
44
|
+
background: var(--el-dialog-overlay-background, transparent);
|
|
45
|
+
opacity: 0;
|
|
46
|
+
transition: opacity var(--el-duration-md, 0s) var(--el-ease, ease);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dialog.showing::backdrop {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
[part~='header'] {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: var(--el-space-2, 0.5rem);
|
|
57
|
+
padding: var(--el-space-4, 1rem);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[part~='title'] {
|
|
61
|
+
flex: 1 1 auto;
|
|
62
|
+
margin: 0;
|
|
63
|
+
font-size: var(--el-font-size-lg, 1.125rem);
|
|
64
|
+
font-weight: var(--el-font-weight-semibold, 600);
|
|
65
|
+
line-height: 1.2;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[part~='header-actions'] {
|
|
69
|
+
display: flex;
|
|
70
|
+
flex: 0 0 auto;
|
|
71
|
+
align-items: center;
|
|
72
|
+
gap: var(--el-space-2, 0.5rem);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
[part~='close-button'] {
|
|
76
|
+
display: inline-flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
padding: 0;
|
|
80
|
+
border: none;
|
|
81
|
+
border-radius: var(--el-radius-md, 0);
|
|
82
|
+
background: transparent;
|
|
83
|
+
color: inherit;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
line-height: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[part~='close-button'] svg {
|
|
89
|
+
width: 1.25rem;
|
|
90
|
+
height: 1.25rem;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
[part~='body'] {
|
|
94
|
+
flex: 1 1 auto;
|
|
95
|
+
overflow: auto;
|
|
96
|
+
padding: var(--el-space-4, 1rem);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Header present: let the header own the top padding so the body doesn't double it. */
|
|
100
|
+
[part~='header'] + [part~='body'] {
|
|
101
|
+
padding-top: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
[part~='footer'] {
|
|
105
|
+
display: flex;
|
|
106
|
+
flex: 0 0 auto;
|
|
107
|
+
justify-content: flex-end;
|
|
108
|
+
gap: var(--el-space-2, 0.5rem);
|
|
109
|
+
padding: var(--el-space-4, 1rem);
|
|
110
|
+
padding-top: 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Collapse the footer entirely when nothing is slotted into it. */
|
|
114
|
+
[part~='footer']:not(:has(*)) {
|
|
115
|
+
display: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@media (prefers-reduced-motion: reduce) {
|
|
119
|
+
dialog,
|
|
120
|
+
dialog::backdrop {
|
|
121
|
+
transition-duration: 0s;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
6
|
+
|
|
7
|
+
<!--
|
|
8
|
+
When your PR touches this component, add an entry under Unreleased and
|
|
9
|
+
mirror it (prefixed with the component name) in root CHANGELOG.md.
|
|
10
|
+
Uncomment headings as needed.
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
## Unreleased
|
|
14
|
+
|
|
15
|
+
## [0.1.0] - 2026-06-03
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `open` custom state on the host. Style with `:host(:state(open))` or `el-dropdown:state(open)` from outside.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- BREAKING: renamed the component — tag `el-dropdown-element` → `el-dropdown`, import subpaths `@webtides/element-library/dropdown-element` → `/dropdown` (and `/dropdown-element/define` → `/dropdown/define`), and exported class `DropdownElement` → `Dropdown`.
|
|
24
|
+
|
|
25
|
+
## Legacy (pre-merge)
|
|
26
|
+
|
|
27
|
+
The version numbers below predate the single-package merge and refer to the component's former standalone npm package, not the current `@webtides/element-library` version. Kept for historical reference.
|
|
28
|
+
|
|
29
|
+
## [0.1.1] - 2021-07-21
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
update element-js version
|
|
34
|
+
|
|
35
|
+
## [0.1.0] - 2020-10-16
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- initial release
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import style from './dropdown.style.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Toggleable dropdown menu with `trigger` and `content` slots. Auto-closes on outside
|
|
6
|
+
* click or `Escape`.
|
|
7
|
+
*
|
|
8
|
+
* @element el-dropdown
|
|
9
|
+
*
|
|
10
|
+
* @slot trigger - Element that opens the dropdown when clicked. Automatically receives
|
|
11
|
+
* the `show-dropdown` attribute.
|
|
12
|
+
* @slot content - Dropdown content shown only while `open` is `true`.
|
|
13
|
+
*
|
|
14
|
+
* @csspart trigger - Forwarded onto the `trigger` slot.
|
|
15
|
+
* @csspart panel - Wrapper around the `content` slot. Surface for background, border, radius
|
|
16
|
+
* and elevation. Only present in the DOM while `open` is `true`.
|
|
17
|
+
* @csspart content - Forwarded onto the `content` slot.
|
|
18
|
+
*
|
|
19
|
+
* @cssstate open - Set while the dropdown content is visible. Style with `:host(:state(open))`
|
|
20
|
+
* or `el-dropdown:state(open)` from outside.
|
|
21
|
+
*
|
|
22
|
+
* @property {boolean} open - Whether the dropdown content is visible. Setting to `true`
|
|
23
|
+
* attaches a one-shot outside-click / `Escape` listener that closes the dropdown.
|
|
24
|
+
*/
|
|
25
|
+
export default class Dropdown extends TemplateElement {
|
|
26
|
+
constructor() {
|
|
27
|
+
super({ styles: [style], shadowRender: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
properties() {
|
|
31
|
+
return {
|
|
32
|
+
open: false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
watch() {
|
|
37
|
+
return {
|
|
38
|
+
open: (open) => {
|
|
39
|
+
if (open) {
|
|
40
|
+
this.addEventListeners();
|
|
41
|
+
this._internals.states.add('open');
|
|
42
|
+
} else {
|
|
43
|
+
this.removeEventListeners();
|
|
44
|
+
this._internals.states.delete('open');
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
events() {
|
|
51
|
+
return {
|
|
52
|
+
'[show-dropdown]': {
|
|
53
|
+
click: () => {
|
|
54
|
+
this.open = true;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @private */
|
|
61
|
+
addEventListeners() {
|
|
62
|
+
window.addEventListener('click', this.onClick.bind(this), { once: true });
|
|
63
|
+
document.addEventListener('keydown', this.onKeyDown.bind(this), { once: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @private */
|
|
67
|
+
removeEventListeners() {
|
|
68
|
+
window.removeEventListener('click', this.onClick);
|
|
69
|
+
document.removeEventListener('keydown', this.onKeyDown);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @private */
|
|
73
|
+
onClick() {
|
|
74
|
+
this.open = false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @private */
|
|
78
|
+
onKeyDown(event) {
|
|
79
|
+
if (event.keyCode === 27) this.open = false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
template() {
|
|
83
|
+
return html`
|
|
84
|
+
<slot part="trigger" name="trigger" show-dropdown></slot>
|
|
85
|
+
${this.open
|
|
86
|
+
? html`
|
|
87
|
+
<div part="panel">
|
|
88
|
+
<slot part="content" name="content"></slot>
|
|
89
|
+
</div>
|
|
90
|
+
`
|
|
91
|
+
: null}
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function define() {
|
|
97
|
+
defineElement('el-dropdown', Dropdown);
|
|
98
|
+
}
|