reke-ui 0.5.1 → 0.5.2
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/custom-elements.json
CHANGED
|
@@ -2117,6 +2117,35 @@
|
|
|
2117
2117
|
"attribute": "position",
|
|
2118
2118
|
"reflects": true
|
|
2119
2119
|
},
|
|
2120
|
+
{
|
|
2121
|
+
"kind": "field",
|
|
2122
|
+
"name": "_previouslyFocused",
|
|
2123
|
+
"type": {
|
|
2124
|
+
"text": "HTMLElement | null"
|
|
2125
|
+
},
|
|
2126
|
+
"privacy": "private",
|
|
2127
|
+
"default": "null",
|
|
2128
|
+
"description": "Element focused before the dialog opened, restored on close."
|
|
2129
|
+
},
|
|
2130
|
+
{
|
|
2131
|
+
"kind": "field",
|
|
2132
|
+
"name": "_previousBodyOverflow",
|
|
2133
|
+
"type": {
|
|
2134
|
+
"text": "string"
|
|
2135
|
+
},
|
|
2136
|
+
"privacy": "private",
|
|
2137
|
+
"default": "''",
|
|
2138
|
+
"description": "Body `overflow` value to put back when the scroll lock is released."
|
|
2139
|
+
},
|
|
2140
|
+
{
|
|
2141
|
+
"kind": "field",
|
|
2142
|
+
"name": "_scrollLocked",
|
|
2143
|
+
"type": {
|
|
2144
|
+
"text": "boolean"
|
|
2145
|
+
},
|
|
2146
|
+
"privacy": "private",
|
|
2147
|
+
"default": "false"
|
|
2148
|
+
},
|
|
2120
2149
|
{
|
|
2121
2150
|
"kind": "field",
|
|
2122
2151
|
"name": "_handleKeydown",
|
|
@@ -2129,6 +2158,66 @@
|
|
|
2129
2158
|
{
|
|
2130
2159
|
"kind": "method",
|
|
2131
2160
|
"name": "close"
|
|
2161
|
+
},
|
|
2162
|
+
{
|
|
2163
|
+
"kind": "method",
|
|
2164
|
+
"name": "getPanel",
|
|
2165
|
+
"privacy": "private",
|
|
2166
|
+
"return": {
|
|
2167
|
+
"type": {
|
|
2168
|
+
"text": "HTMLElement | null"
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
},
|
|
2172
|
+
{
|
|
2173
|
+
"kind": "method",
|
|
2174
|
+
"name": "getFocusableElements",
|
|
2175
|
+
"privacy": "private",
|
|
2176
|
+
"return": {
|
|
2177
|
+
"type": {
|
|
2178
|
+
"text": "HTMLElement[]"
|
|
2179
|
+
}
|
|
2180
|
+
},
|
|
2181
|
+
"description": "Focusable descendants in tab order: the shadow close button first, then\nthe default slot, then the footer slot — matching how the panel reads."
|
|
2182
|
+
},
|
|
2183
|
+
{
|
|
2184
|
+
"kind": "method",
|
|
2185
|
+
"name": "getSlottedFocusable",
|
|
2186
|
+
"privacy": "private",
|
|
2187
|
+
"return": {
|
|
2188
|
+
"type": {
|
|
2189
|
+
"text": "HTMLElement[]"
|
|
2190
|
+
}
|
|
2191
|
+
},
|
|
2192
|
+
"parameters": [
|
|
2193
|
+
{
|
|
2194
|
+
"name": "name",
|
|
2195
|
+
"optional": true,
|
|
2196
|
+
"type": {
|
|
2197
|
+
"text": "string"
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
]
|
|
2201
|
+
},
|
|
2202
|
+
{
|
|
2203
|
+
"kind": "method",
|
|
2204
|
+
"name": "handleOpened",
|
|
2205
|
+
"privacy": "private"
|
|
2206
|
+
},
|
|
2207
|
+
{
|
|
2208
|
+
"kind": "method",
|
|
2209
|
+
"name": "handleClosed",
|
|
2210
|
+
"privacy": "private"
|
|
2211
|
+
},
|
|
2212
|
+
{
|
|
2213
|
+
"kind": "method",
|
|
2214
|
+
"name": "lockScroll",
|
|
2215
|
+
"privacy": "private"
|
|
2216
|
+
},
|
|
2217
|
+
{
|
|
2218
|
+
"kind": "method",
|
|
2219
|
+
"name": "releaseScrollLock",
|
|
2220
|
+
"privacy": "private"
|
|
2132
2221
|
}
|
|
2133
2222
|
],
|
|
2134
2223
|
"events": [
|
|
@@ -2178,7 +2267,7 @@
|
|
|
2178
2267
|
},
|
|
2179
2268
|
"tagName": "reke-dialog",
|
|
2180
2269
|
"customElement": true,
|
|
2181
|
-
"summary": "A dialog component with modal and drawer variants."
|
|
2270
|
+
"summary": "A dialog component with modal and drawer variants.\n\nImplements the ARIA dialog pattern: while open it takes focus, keeps Tab\ncycling inside the panel, restores focus to whatever opened it, and locks\nbody scroll."
|
|
2182
2271
|
}
|
|
2183
2272
|
],
|
|
2184
2273
|
"exports": [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nothing } from 'lit';
|
|
1
|
+
import { nothing, type PropertyValues } from 'lit';
|
|
2
2
|
import { RekeElement } from '../../shared/base-element.js';
|
|
3
3
|
export type DialogVariant = 'modal' | 'drawer';
|
|
4
4
|
export type DrawerPosition = 'right' | 'left';
|
|
@@ -6,6 +6,10 @@ export type DrawerPosition = 'right' | 'left';
|
|
|
6
6
|
* @tag reke-dialog
|
|
7
7
|
* @summary A dialog component with modal and drawer variants.
|
|
8
8
|
*
|
|
9
|
+
* Implements the ARIA dialog pattern: while open it takes focus, keeps Tab
|
|
10
|
+
* cycling inside the panel, restores focus to whatever opened it, and locks
|
|
11
|
+
* body scroll.
|
|
12
|
+
*
|
|
9
13
|
* @slot - Default slot for dialog body content.
|
|
10
14
|
* @slot footer - Slot for action buttons.
|
|
11
15
|
*
|
|
@@ -24,11 +28,28 @@ export declare class RekeDialog extends RekeElement {
|
|
|
24
28
|
variant: DialogVariant;
|
|
25
29
|
/** Drawer slide direction. Only applies when variant="drawer". */
|
|
26
30
|
position: DrawerPosition;
|
|
31
|
+
/** Element focused before the dialog opened, restored on close. */
|
|
32
|
+
private _previouslyFocused;
|
|
33
|
+
/** Body `overflow` value to put back when the scroll lock is released. */
|
|
34
|
+
private _previousBodyOverflow;
|
|
35
|
+
private _scrollLocked;
|
|
27
36
|
private _handleKeydown;
|
|
28
37
|
connectedCallback(): void;
|
|
29
38
|
disconnectedCallback(): void;
|
|
39
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
30
40
|
show(): void;
|
|
31
41
|
close(): void;
|
|
42
|
+
private getPanel;
|
|
43
|
+
/**
|
|
44
|
+
* Focusable descendants in tab order: the shadow close button first, then
|
|
45
|
+
* the default slot, then the footer slot — matching how the panel reads.
|
|
46
|
+
*/
|
|
47
|
+
private getFocusableElements;
|
|
48
|
+
private getSlottedFocusable;
|
|
49
|
+
private handleOpened;
|
|
50
|
+
private handleClosed;
|
|
51
|
+
private lockScroll;
|
|
52
|
+
private releaseScrollLock;
|
|
32
53
|
render(): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
33
54
|
}
|
|
34
55
|
declare global {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reke-dialog.d.ts","sourceRoot":"","sources":["../../../src/components/reke-dialog/reke-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"reke-dialog.d.ts","sourceRoot":"","sources":["../../../src/components/reke-dialog/reke-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAC;AAC/C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,CAAC;AAW9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBACa,UAAW,SAAQ,WAAW;IACzC,OAAgB,MAAM,4BAAU;IAGhC,IAAI,UAAS;IAGb,OAAO,SAAM;IAGb,OAAO,EAAE,aAAa,CAAW;IAEjC,kEAAkE;IAElE,QAAQ,EAAE,cAAc,CAAW;IAEnC,mEAAmE;IACnE,OAAO,CAAC,kBAAkB,CAA4B;IAEtD,0EAA0E;IAC1E,OAAO,CAAC,qBAAqB,CAAM;IACnC,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,cAAc,CAiCpB;IAEO,iBAAiB;IAKjB,oBAAoB;cAOV,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAUxD,IAAI;IAIJ,KAAK;IAKL,OAAO,CAAC,QAAQ;IAIhB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,iBAAiB;IAMhB,MAAM;CAqDhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAC;KAC3B;CACF"}
|
|
@@ -5,10 +5,29 @@ import { html as r, nothing as i } from "lit";
|
|
|
5
5
|
import { customElement as a, property as o } from "lit/decorators.js";
|
|
6
6
|
import { classMap as s } from "lit/directives/class-map.js";
|
|
7
7
|
//#region src/components/reke-dialog/reke-dialog.ts
|
|
8
|
-
var c =
|
|
8
|
+
var c = [
|
|
9
|
+
"a[href]",
|
|
10
|
+
"button:not([disabled])",
|
|
11
|
+
"input:not([disabled])",
|
|
12
|
+
"select:not([disabled])",
|
|
13
|
+
"textarea:not([disabled])",
|
|
14
|
+
"[tabindex]:not([tabindex=\"-1\"])"
|
|
15
|
+
].join(","), l = class extends e {
|
|
9
16
|
constructor(...e) {
|
|
10
|
-
super(...e), this.open = !1, this.heading = "", this.variant = "modal", this.position = "right", this._handleKeydown = (e) => {
|
|
11
|
-
|
|
17
|
+
super(...e), this.open = !1, this.heading = "", this.variant = "modal", this.position = "right", this._previouslyFocused = null, this._previousBodyOverflow = "", this._scrollLocked = !1, this._handleKeydown = (e) => {
|
|
18
|
+
if (!this.open) return;
|
|
19
|
+
if (e.key === "Escape") {
|
|
20
|
+
this.close();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (e.key !== "Tab") return;
|
|
24
|
+
let t = this.getFocusableElements();
|
|
25
|
+
if (t.length === 0) {
|
|
26
|
+
e.preventDefault(), this.getPanel()?.focus();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let n = this.shadowRoot?.activeElement ?? document.activeElement, r = n ? t.indexOf(n) : -1;
|
|
30
|
+
e.shiftKey ? r <= 0 && (e.preventDefault(), t[t.length - 1].focus()) : (r === -1 || r === t.length - 1) && (e.preventDefault(), t[0].focus());
|
|
12
31
|
};
|
|
13
32
|
}
|
|
14
33
|
static {
|
|
@@ -18,7 +37,10 @@ var c = class extends e {
|
|
|
18
37
|
super.connectedCallback(), document.addEventListener("keydown", this._handleKeydown);
|
|
19
38
|
}
|
|
20
39
|
disconnectedCallback() {
|
|
21
|
-
super.disconnectedCallback(), document.removeEventListener("keydown", this._handleKeydown);
|
|
40
|
+
super.disconnectedCallback(), document.removeEventListener("keydown", this._handleKeydown), this.releaseScrollLock();
|
|
41
|
+
}
|
|
42
|
+
updated(e) {
|
|
43
|
+
e.has("open") && (this.open ? this.handleOpened() : e.get("open") === !0 && this.handleClosed());
|
|
22
44
|
}
|
|
23
45
|
show() {
|
|
24
46
|
this.open = !0;
|
|
@@ -26,6 +48,38 @@ var c = class extends e {
|
|
|
26
48
|
close() {
|
|
27
49
|
this.open = !1, this.emit("reke-close");
|
|
28
50
|
}
|
|
51
|
+
getPanel() {
|
|
52
|
+
return this.shadowRoot?.querySelector(".dialog, .drawer") ?? null;
|
|
53
|
+
}
|
|
54
|
+
getFocusableElements() {
|
|
55
|
+
let e = this.shadowRoot?.querySelector(".close-btn");
|
|
56
|
+
return [
|
|
57
|
+
...e ? [e] : [],
|
|
58
|
+
...this.getSlottedFocusable(),
|
|
59
|
+
...this.getSlottedFocusable("footer")
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
getSlottedFocusable(e) {
|
|
63
|
+
let t = e ? `slot[name="${e}"]` : "slot:not([name])", n = this.shadowRoot?.querySelector(t);
|
|
64
|
+
if (!n) return [];
|
|
65
|
+
let r = [];
|
|
66
|
+
for (let e of n.assignedElements()) e instanceof HTMLElement && (e.matches(c) && r.push(e), r.push(...e.querySelectorAll(c)));
|
|
67
|
+
return r;
|
|
68
|
+
}
|
|
69
|
+
handleOpened() {
|
|
70
|
+
this._previouslyFocused = document.activeElement, this.lockScroll(), (this.getFocusableElements()[0] ?? this.getPanel())?.focus();
|
|
71
|
+
}
|
|
72
|
+
handleClosed() {
|
|
73
|
+
this.releaseScrollLock();
|
|
74
|
+
let e = this._previouslyFocused;
|
|
75
|
+
this._previouslyFocused = null, e?.focus();
|
|
76
|
+
}
|
|
77
|
+
lockScroll() {
|
|
78
|
+
this._scrollLocked ||= (this._previousBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
|
|
79
|
+
}
|
|
80
|
+
releaseScrollLock() {
|
|
81
|
+
this._scrollLocked &&= (document.body.style.overflow = this._previousBodyOverflow, !1);
|
|
82
|
+
}
|
|
29
83
|
render() {
|
|
30
84
|
if (!this.open) return i;
|
|
31
85
|
let e = this.variant === "drawer", t = {
|
|
@@ -44,6 +98,7 @@ var c = class extends e {
|
|
|
44
98
|
role="dialog"
|
|
45
99
|
aria-modal="true"
|
|
46
100
|
aria-label=${this.heading}
|
|
101
|
+
tabindex="-1"
|
|
47
102
|
@click=${(e) => e.stopPropagation()}
|
|
48
103
|
>
|
|
49
104
|
${this.heading ? r`
|
|
@@ -72,6 +127,6 @@ var c = class extends e {
|
|
|
72
127
|
t([o({
|
|
73
128
|
type: Boolean,
|
|
74
129
|
reflect: !0
|
|
75
|
-
})],
|
|
130
|
+
})], l.prototype, "open", void 0), t([o()], l.prototype, "heading", void 0), t([o({ reflect: !0 })], l.prototype, "variant", void 0), t([o({ reflect: !0 })], l.prototype, "position", void 0), l = t([a("reke-dialog")], l);
|
|
76
131
|
//#endregion
|
|
77
|
-
export {
|
|
132
|
+
export { l as RekeDialog };
|