@shortfuse/materialdesignweb 0.4.0 → 0.5.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/.browserslistrc +2 -1
- package/.eslintrc.json +59 -8
- package/.stylelintrc.json +94 -49
- package/CHANGELOG.md +12 -0
- package/README.md +1 -3
- package/adapters/datatable/column.js +27 -54
- package/adapters/datatable/index.js +69 -81
- package/adapters/dom/index.js +32 -47
- package/adapters/search/index.js +107 -133
- package/components/appbar/_spec.scss +77 -137
- package/components/banner/_spec.scss +28 -63
- package/components/bottomnav/_spec.scss +46 -54
- package/components/bottomnav/index.js +15 -20
- package/components/bottomnav/item.js +4 -5
- package/components/button/README.md +1 -1
- package/components/button/_spec.scss +43 -42
- package/components/button/_theme.scss +27 -50
- package/components/card/_spec.scss +61 -69
- package/components/chip/_spec.scss +21 -44
- package/components/chip/_theme.scss +79 -151
- package/components/chip/index.js +6 -4
- package/components/datatable/_spec.scss +36 -99
- package/components/datatable/_theme.scss +98 -124
- package/components/datatable/cell.js +1 -2
- package/components/datatable/columnheader.js +1 -2
- package/components/datatable/index.js +33 -47
- package/components/datatable/row.js +4 -5
- package/components/dialog/_spec.scss +53 -63
- package/components/dialog/_theme.scss +7 -0
- package/components/dialog/index.js +62 -88
- package/components/divider/_spec.scss +6 -8
- package/components/elevation/_spec.scss +1 -1
- package/components/fab/_spec.scss +30 -42
- package/components/fab/index.js +4 -8
- package/components/grid/_spec.scss +68 -211
- package/components/layout/_mixins.scss +0 -22
- package/components/layout/_spec.scss +267 -363
- package/components/layout/_theme.scss +10 -35
- package/components/layout/index.js +40 -50
- package/components/list/_spec.scss +57 -91
- package/components/list/_theme.scss +75 -84
- package/components/list/content.js +9 -13
- package/components/list/index.js +34 -38
- package/components/list/item.js +8 -11
- package/components/list/secondary.js +8 -9
- package/components/menu/_spec.scss +134 -167
- package/components/menu/index.js +45 -61
- package/components/menu/item.js +11 -19
- package/components/progress/_spec.scss +43 -34
- package/components/selection/_spec.scss +123 -133
- package/components/selection/_theme.scss +88 -120
- package/components/selection/index.js +9 -15
- package/components/selection/input.js +3 -5
- package/components/selection/radiogroup.js +8 -15
- package/components/slider/_spec.scss +23 -28
- package/components/snackbar/_spec.scss +17 -62
- package/components/snackbar/index.js +15 -21
- package/components/tab/_spec.scss +35 -50
- package/components/tab/content.js +33 -28
- package/components/tab/index.js +30 -33
- package/components/tab/item.js +4 -5
- package/components/tab/list.js +22 -36
- package/components/textfield/README.md +2 -2
- package/components/textfield/_spec.scss +241 -287
- package/components/textfield/_theme.scss +197 -232
- package/components/textfield/index.js +8 -16
- package/components/tooltip/_spec.scss +23 -26
- package/components/type/_spec.scss +19 -16
- package/core/_breakpoint.scss +33 -33
- package/core/_elevation.scss +40 -0
- package/core/_length.scss +0 -1
- package/core/_platform.scss +0 -22
- package/core/_type.scss +7 -6
- package/core/aria/button.js +4 -5
- package/core/aria/keyboard.js +1 -2
- package/core/aria/rovingtabindex.js +14 -17
- package/core/aria/tab.js +1 -2
- package/core/dom.js +18 -109
- package/core/overlay/_spec.scss +5 -8
- package/core/overlay/_theme.scss +126 -150
- package/core/overlay/index.js +19 -32
- package/core/ripple/_spec.scss +16 -17
- package/core/ripple/_theme.scss +13 -33
- package/core/ripple/index.js +36 -44
- package/core/theme/_aliases.scss +15 -0
- package/core/theme/_config.scss +8 -2
- package/core/theme/_functions.scss +22 -0
- package/core/theme/_palettes.scss +0 -1
- package/core/{color → theme}/_spec.scss +0 -0
- package/core/theme/_theme.scss +268 -0
- package/core/theme/index.scss +4 -0
- package/core/transition/index.js +73 -76
- package/docs/_flex.scss +7 -1
- package/docs/_menuoptions.js +2 -2
- package/docs/_partials/_appbar.eta +12 -14
- package/docs/_partials/_header.eta +41 -44
- package/docs/_sample-utils.js +15 -20
- package/docs/docs.scss +123 -87
- package/docs/framework.scss +26 -0
- package/docs/index.eta +2 -6
- package/docs/index.js +7 -0
- package/docs/pages/appbar.eta +22 -28
- package/docs/pages/bottomnav.js +17 -14
- package/docs/pages/button.js +10 -10
- package/docs/pages/card.js +20 -22
- package/docs/pages/chip.js +11 -13
- package/docs/pages/color.js +35 -36
- package/docs/pages/datatable.js +11 -15
- package/docs/pages/dialog.eta +9 -11
- package/docs/pages/dialog.js +6 -9
- package/docs/pages/dom.js +6 -9
- package/docs/pages/elevation.eta +10 -10
- package/docs/pages/fab.js +2 -3
- package/docs/pages/grid.js +5 -5
- package/docs/pages/list.js +1 -2
- package/docs/pages/menu.eta +17 -19
- package/docs/pages/menu.js +7 -11
- package/docs/pages/overlay.js +1 -2
- package/docs/pages/progress.eta +2 -2
- package/docs/pages/progress.js +1 -1
- package/docs/pages/ripple.js +1 -2
- package/docs/pages/search.eta +20 -24
- package/docs/pages/search.js +24 -41
- package/docs/pages/selection.eta +2 -6
- package/docs/pages/selection.js +3 -4
- package/docs/pages/snackbar.js +3 -4
- package/docs/pages/tab.eta +61 -75
- package/docs/pages/tab.js +16 -15
- package/docs/pages/textfield.eta +9 -8
- package/docs/pages/textfield.js +26 -23
- package/docs/pages/tooltip.eta +10 -12
- package/docs/pages/transition.js +5 -7
- package/docs/postrender.js +7 -5
- package/docs/pwa/pwa.eta +14 -16
- package/docs/pwa/pwa.js +19 -27
- package/docs/pwa/pwa.scss +12 -7
- package/docs/themes/theme-colored.scss +9 -11
- package/docs/themes/theme-default.scss +0 -14
- package/index.scss +27 -0
- package/jsconfig.json +7 -3
- package/package.json +26 -15
- package/tsconfig.json +16 -0
- package/{webpack.config.cjs → webpack.config.js} +105 -58
- package/components/template/_theme.scss +0 -27
- package/components/textfield/_mixins.scss +0 -52
- package/core/color/_theme.scss +0 -390
- package/core/color/index.scss +0 -2
- package/core/theme/_mixins.scss +0 -172
- package/core/theme/_variables.scss +0 -24
- package/docs/_mixins.pug +0 -155
- package/docs/pages/appbar.pug +0 -78
- package/docs/pages/bottomnav.pug +0 -137
- package/docs/pages/button.pug +0 -121
- package/docs/pages/card.pug +0 -74
- package/docs/pages/chip.pug +0 -91
- package/docs/pages/color.pug +0 -121
- package/docs/pages/datatable.pug +0 -283
- package/docs/pages/dialog.pug +0 -132
- package/docs/pages/dom.pug +0 -22
- package/docs/pages/elevation.pug +0 -25
- package/docs/pages/fab.pug +0 -66
- package/docs/pages/grid.pug +0 -95
- package/docs/pages/layout.pug +0 -7
- package/docs/pages/list.pug +0 -326
- package/docs/pages/menu.pug +0 -205
- package/docs/pages/overlay.pug +0 -55
- package/docs/pages/progress.pug +0 -16
- package/docs/pages/ripple.pug +0 -21
- package/docs/pages/search.pug +0 -165
- package/docs/pages/selection.pug +0 -74
- package/docs/pages/slider.pug +0 -17
- package/docs/pages/snackbar.pug +0 -60
- package/docs/pages/tab.pug +0 -304
- package/docs/pages/textfield.pug +0 -360
- package/docs/pages/tooltip.pug +0 -78
- package/docs/pages/transition.pug +0 -76
- package/docs/pages/type.pug +0 -29
- package/docs/pwa/_dialogs.pug +0 -96
- package/docs/pwa/_menus.pug +0 -11
- package/docs/pwa/pwa.pug +0 -325
- package/docs/spec.scss +0 -26
- package/docs/themes/_component-themes.scss +0 -26
- package/docs/themes/theme-colored-fallbacks.scss +0 -17
- package/docs/themes/theme-default-fallbacks.scss +0 -17
|
@@ -6,28 +6,26 @@
|
|
|
6
6
|
@use '../../core/_motion.scss' as motion;
|
|
7
7
|
@use '../../core/_type.scss' as type;
|
|
8
8
|
|
|
9
|
-
$unitWidth:
|
|
9
|
+
$unitWidth: 56px !default;
|
|
10
10
|
|
|
11
11
|
.mdw-dialog__close {
|
|
12
12
|
position: absolute;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
inset-block-start: 0;
|
|
14
|
+
inset-inline-start: 0;
|
|
15
15
|
// Scroll mask
|
|
16
|
-
-ms-overflow-style: none;
|
|
17
16
|
overflow-y: scroll;
|
|
18
17
|
overscroll-behavior: none;
|
|
19
18
|
overscroll-behavior: contain;
|
|
20
|
-
-ms-scroll-chaining: none;
|
|
21
19
|
scrollbar-width: none;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
|
|
21
|
+
block-size: 100%;
|
|
22
|
+
inline-size: 100%;
|
|
23
|
+
|
|
27
24
|
cursor: default;
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
|
|
30
26
|
pointer-events: inherit;
|
|
27
|
+
-webkit-tap-highlight-color: transparent;
|
|
28
|
+
|
|
31
29
|
visibility: hidden;
|
|
32
30
|
z-index: 8;
|
|
33
31
|
|
|
@@ -37,39 +35,43 @@ $unitWidth: dp(56) !default;
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
&::after {
|
|
40
|
-
display: block;
|
|
41
38
|
content: '';
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
display: block;
|
|
41
|
+
|
|
42
|
+
block-size: 200%;
|
|
43
|
+
inline-size: 200%;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
.mdw-dialog {
|
|
49
48
|
display: flex;
|
|
50
49
|
position: absolute;
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
inset-block-start: 0;
|
|
51
|
+
inset-inline-start: 0;
|
|
52
|
+
|
|
53
53
|
align-items: center;
|
|
54
54
|
flex-direction: row;
|
|
55
55
|
justify-content: center;
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
box-sizing: border-box;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
padding:
|
|
61
|
-
|
|
58
|
+
block-size: 100%;
|
|
59
|
+
inline-size: 100%;
|
|
60
|
+
padding: 84px 40px;
|
|
61
|
+
|
|
62
|
+
pointer-events: none;
|
|
63
|
+
|
|
62
64
|
transition-duration: motion.$fadeOutDuration;
|
|
63
65
|
transition-property: opacity;
|
|
64
66
|
transition-timing-function: motion.$accelerateEasing;
|
|
65
67
|
will-change: opacity;
|
|
66
|
-
|
|
68
|
+
|
|
67
69
|
opacity: 0;
|
|
68
|
-
pointer-events: none;
|
|
69
70
|
|
|
70
71
|
z-index: 24;
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
/* Handled by theme */
|
|
74
|
+
// background-color: rgba(0, 0, 0, 0.50);
|
|
73
75
|
|
|
74
76
|
&:not([aria-hidden]) {
|
|
75
77
|
// Initial state
|
|
@@ -79,7 +81,7 @@ $unitWidth: dp(56) !default;
|
|
|
79
81
|
@for $i from 3 to 8 {
|
|
80
82
|
&[mdw-width-units="#{$i}"] {
|
|
81
83
|
.mdw-dialog__popup {
|
|
82
|
-
min-
|
|
84
|
+
min-inline-size: #{$unitWidth * $i};
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -94,31 +96,31 @@ $unitWidth: dp(56) !default;
|
|
|
94
96
|
|
|
95
97
|
overscroll-behavior: none;
|
|
96
98
|
overscroll-behavior: contain;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
max-width: 100%;
|
|
99
|
+
|
|
100
|
+
max-block-size: 100%;
|
|
101
|
+
min-inline-size: 224px;
|
|
102
|
+
max-inline-size: 100%;
|
|
102
103
|
flex-shrink: 1;
|
|
103
104
|
|
|
104
105
|
will-change: display, transform;
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
transform: scale(1);
|
|
107
108
|
transform-origin: bottom center;
|
|
108
109
|
z-index: 24;
|
|
109
110
|
|
|
110
|
-
border-radius:
|
|
111
|
+
border-radius: 4px;
|
|
111
112
|
box-shadow: elevation.boxShadow(24);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
.mdw-dialog[aria-hidden="false"],
|
|
115
116
|
.mdw-dialog[id]:target {
|
|
117
|
+
pointer-events: auto;
|
|
118
|
+
|
|
116
119
|
transition-duration: motion.$fadeInDuration;
|
|
117
120
|
transition-property: opacity;
|
|
118
121
|
transition-timing-function: motion.$decelerateEasing;
|
|
119
122
|
|
|
120
123
|
opacity: 1;
|
|
121
|
-
pointer-events: auto;
|
|
122
124
|
|
|
123
125
|
.mdw-dialog__close {
|
|
124
126
|
visibility: visible;
|
|
@@ -150,8 +152,8 @@ $unitWidth: dp(56) !default;
|
|
|
150
152
|
@include type.addRules('h6');
|
|
151
153
|
@include type.baselineToBottom(36);
|
|
152
154
|
|
|
153
|
-
margin-
|
|
154
|
-
padding: 0
|
|
155
|
+
margin-block-end: -36px;
|
|
156
|
+
padding: 0 24px;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
.mdw-dialog__body {
|
|
@@ -159,11 +161,11 @@ $unitWidth: dp(56) !default;
|
|
|
159
161
|
@include type.addRules('body');
|
|
160
162
|
@include type.baselineToBottom(28);
|
|
161
163
|
|
|
162
|
-
padding: 0
|
|
164
|
+
padding: 0 24px;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
.mdw-dialog__header {
|
|
166
|
-
min-
|
|
168
|
+
min-block-size: 64px;
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
.mdw-dialog__scrolling {
|
|
@@ -175,39 +177,27 @@ $unitWidth: dp(56) !default;
|
|
|
175
177
|
flex-direction: row-reverse;
|
|
176
178
|
flex-wrap: wrap;
|
|
177
179
|
justify-content: flex-start;
|
|
178
|
-
|
|
180
|
+
|
|
179
181
|
flex: none;
|
|
180
|
-
margin-
|
|
181
|
-
|
|
182
|
+
margin-block: 8px;
|
|
183
|
+
|
|
184
|
+
.mdw-button {
|
|
185
|
+
margin-inline: 0 8px;
|
|
186
|
+
|
|
187
|
+
text-align: end;
|
|
188
|
+
}
|
|
182
189
|
|
|
183
190
|
&[mdw-stacked] {
|
|
184
|
-
margin-
|
|
191
|
+
margin-block-start: 0;
|
|
185
192
|
|
|
186
193
|
.mdw-button {
|
|
187
194
|
justify-content: flex-end;
|
|
188
|
-
|
|
189
|
-
min-height: dp(48);
|
|
190
|
-
flex-basis: 100%;
|
|
191
|
-
margin-right: 0;
|
|
192
|
-
padding-right: dp(16);
|
|
193
|
-
padding-left: dp(16);
|
|
194
|
-
|
|
195
|
-
&,
|
|
196
|
-
:root[dir="rtl"] & {
|
|
197
|
-
margin-left: 0;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
195
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
text-align: end;
|
|
196
|
+
min-block-size: 48px;
|
|
197
|
+
flex-basis: 100%;
|
|
198
|
+
margin-inline: 0;
|
|
199
|
+
padding-inline: 16px;
|
|
207
200
|
|
|
208
|
-
:root[dir="rtl"] & {
|
|
209
|
-
margin-right: 0;
|
|
210
|
-
margin-left: dp(8);
|
|
211
201
|
}
|
|
212
202
|
}
|
|
213
203
|
}
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
dispatchDomEvent,
|
|
5
|
-
findElementParentByClassName,
|
|
6
5
|
getChildElementByClass,
|
|
7
|
-
iterateArrayLike,
|
|
8
|
-
iterateSomeOfArrayLike,
|
|
9
6
|
setTextNode,
|
|
10
7
|
} from '../../core/dom.js';
|
|
11
8
|
import * as Button from '../button/index.js';
|
|
@@ -13,13 +10,13 @@ import * as Button from '../button/index.js';
|
|
|
13
10
|
class DialogStack {
|
|
14
11
|
/**
|
|
15
12
|
* @param {Element} element
|
|
16
|
-
* @param {Element} previousFocus
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
13
|
+
* @param {?Element} [previousFocus]
|
|
14
|
+
* @param {{hash:string}} [state]
|
|
15
|
+
* @param {{hash:string}} [previousState]
|
|
19
16
|
*/
|
|
20
17
|
constructor(element, previousFocus, state, previousState) {
|
|
21
|
-
this.element =
|
|
22
|
-
this.previousFocus =
|
|
18
|
+
this.element = element;
|
|
19
|
+
this.previousFocus = previousFocus;
|
|
23
20
|
this.state = state;
|
|
24
21
|
this.previousState = previousState;
|
|
25
22
|
}
|
|
@@ -41,13 +38,11 @@ export function onTransitionEnd(event) {
|
|
|
41
38
|
if (event.propertyName !== 'opacity') {
|
|
42
39
|
return;
|
|
43
40
|
}
|
|
44
|
-
/** @type {HTMLElement} */
|
|
45
|
-
const dialogElement = (event.currentTarget);
|
|
41
|
+
const dialogElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
46
42
|
if (dialogElement.getAttribute('aria-hidden') !== 'true') {
|
|
47
43
|
return;
|
|
48
44
|
}
|
|
49
|
-
/** @type {HTMLElement} */
|
|
50
|
-
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
45
|
+
const popupElement = /** @type {HTMLElement} */ (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
51
46
|
if (!popupElement) {
|
|
52
47
|
return;
|
|
53
48
|
}
|
|
@@ -103,22 +98,18 @@ export function hide(dialogElement) {
|
|
|
103
98
|
});
|
|
104
99
|
if (stackIndex !== -1) {
|
|
105
100
|
const stack = OPEN_DIALOGS[stackIndex];
|
|
106
|
-
if (stack.previousFocus && stack.previousFocus instanceof HTMLElement) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// Failed to focus
|
|
113
|
-
}
|
|
101
|
+
if (stack.previousFocus && stack.previousFocus instanceof HTMLElement && document.activeElement?.closest('.mdw-dialog') === dialogElement) {
|
|
102
|
+
// Only pop focus back when hiding a dialog with focus within itself.
|
|
103
|
+
try {
|
|
104
|
+
stack.previousFocus.focus();
|
|
105
|
+
} catch {
|
|
106
|
+
// Failed to focus
|
|
114
107
|
}
|
|
115
108
|
}
|
|
116
109
|
OPEN_DIALOGS.splice(stackIndex, 1);
|
|
117
|
-
if (stack.state && window.history && window.history.state
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
window.history.back();
|
|
121
|
-
}
|
|
110
|
+
if (stack.state && window.history && window.history.state // IE11 returns a cloned state object, not the original
|
|
111
|
+
&& stack.state.hash === window.history.state.hash) {
|
|
112
|
+
window.history.back();
|
|
122
113
|
}
|
|
123
114
|
}
|
|
124
115
|
if (!OPEN_DIALOGS.length) {
|
|
@@ -156,9 +147,8 @@ export function onCancelClick(event) {
|
|
|
156
147
|
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
157
148
|
event.preventDefault();
|
|
158
149
|
}
|
|
159
|
-
/** @type {HTMLElement} */
|
|
160
|
-
const
|
|
161
|
-
const dialogElement = findElementParentByClassName(cancelElement, 'mdw-dialog');
|
|
150
|
+
const cancelElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
151
|
+
const dialogElement = cancelElement.closest('.mdw-dialog');
|
|
162
152
|
cancel(dialogElement);
|
|
163
153
|
}
|
|
164
154
|
|
|
@@ -170,9 +160,8 @@ export function onConfirmClick(event) {
|
|
|
170
160
|
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
171
161
|
event.preventDefault();
|
|
172
162
|
}
|
|
173
|
-
/** @type {HTMLElement} */
|
|
174
|
-
const
|
|
175
|
-
const dialogElement = findElementParentByClassName(button, 'mdw-dialog');
|
|
163
|
+
const button = /** @type {HTMLElement} */ (event.currentTarget);
|
|
164
|
+
const dialogElement = button.closest('.mdw-dialog');
|
|
176
165
|
confirm(dialogElement);
|
|
177
166
|
}
|
|
178
167
|
|
|
@@ -184,10 +173,9 @@ export function onCustomButtonClick(event) {
|
|
|
184
173
|
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
185
174
|
event.preventDefault();
|
|
186
175
|
}
|
|
187
|
-
/** @type {HTMLElement} */
|
|
188
|
-
const button = (event.currentTarget);
|
|
176
|
+
const button = /** @type {HTMLElement} */ (event.currentTarget);
|
|
189
177
|
if (dispatchDomEvent(button, CUSTOM_EVENT)) {
|
|
190
|
-
const dialogElement =
|
|
178
|
+
const dialogElement = button.closest('.mdw-dialog');
|
|
191
179
|
hide(dialogElement);
|
|
192
180
|
}
|
|
193
181
|
}
|
|
@@ -197,8 +185,7 @@ export function onCustomButtonClick(event) {
|
|
|
197
185
|
* @return {void}
|
|
198
186
|
*/
|
|
199
187
|
export function handleTabKeyPress(event) {
|
|
200
|
-
/** @type {Element} */
|
|
201
|
-
const popupElement = (event.currentTarget);
|
|
188
|
+
const popupElement = /** @type {Element} */ (event.currentTarget);
|
|
202
189
|
const focusableElements = popupElement.querySelectorAll([
|
|
203
190
|
'button:not(:disabled):not([tabindex="-1"])',
|
|
204
191
|
'[href]:not(:disabled):not([tabindex="-1"])',
|
|
@@ -208,35 +195,28 @@ export function handleTabKeyPress(event) {
|
|
|
208
195
|
'[tabindex]:not([tabindex="-1"])'].join(', '));
|
|
209
196
|
let foundTarget = false;
|
|
210
197
|
let candidate = null;
|
|
211
|
-
|
|
198
|
+
for (const el of focusableElements) {
|
|
212
199
|
if (el === event.target) {
|
|
213
200
|
foundTarget = true;
|
|
214
201
|
if (event.shiftKey) {
|
|
215
|
-
|
|
202
|
+
break;
|
|
216
203
|
}
|
|
217
204
|
} else if (event.shiftKey) {
|
|
218
205
|
candidate = el;
|
|
219
206
|
} else if (foundTarget) {
|
|
220
207
|
candidate = el;
|
|
221
|
-
|
|
208
|
+
break;
|
|
222
209
|
}
|
|
223
|
-
|
|
224
|
-
});
|
|
210
|
+
}
|
|
225
211
|
if (!candidate) {
|
|
226
|
-
|
|
227
|
-
// Select last item
|
|
228
|
-
candidate = focusableElements[focusableElements.length - 1];
|
|
229
|
-
} else {
|
|
230
|
-
// Select first item
|
|
231
|
-
candidate = focusableElements[0];
|
|
232
|
-
}
|
|
212
|
+
candidate = event.shiftKey ? focusableElements[focusableElements.length - 1] : focusableElements[0];
|
|
233
213
|
}
|
|
234
214
|
event.stopPropagation();
|
|
235
215
|
event.preventDefault();
|
|
236
216
|
if (candidate && candidate instanceof HTMLElement) {
|
|
237
217
|
try {
|
|
238
218
|
candidate.focus();
|
|
239
|
-
} catch
|
|
219
|
+
} catch {
|
|
240
220
|
// Failed to focus
|
|
241
221
|
}
|
|
242
222
|
}
|
|
@@ -249,9 +229,8 @@ export function handleTabKeyPress(event) {
|
|
|
249
229
|
export function onEscapeKeyDown(event) {
|
|
250
230
|
event.stopPropagation();
|
|
251
231
|
event.preventDefault();
|
|
252
|
-
/** @type {HTMLElement} */
|
|
253
|
-
const
|
|
254
|
-
const dialogElement = findElementParentByClassName(popupElement, 'mdw-dialog');
|
|
232
|
+
const popupElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
233
|
+
const dialogElement = popupElement.closest('.mdw-dialog');
|
|
255
234
|
cancel(dialogElement);
|
|
256
235
|
}
|
|
257
236
|
|
|
@@ -277,11 +256,11 @@ export function getTitleText(dialogElement) {
|
|
|
277
256
|
let title = 'Dialog';
|
|
278
257
|
const titleElement = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
279
258
|
if (titleElement) {
|
|
280
|
-
title = titleElement.textContent;
|
|
259
|
+
title = titleElement.textContent ?? '';
|
|
281
260
|
} else {
|
|
282
261
|
const bodyElement = dialogElement.getElementsByClassName('mdw-dialog__body')[0];
|
|
283
262
|
if (bodyElement) {
|
|
284
|
-
title = bodyElement.textContent;
|
|
263
|
+
title = bodyElement.textContent ?? '';
|
|
285
264
|
}
|
|
286
265
|
}
|
|
287
266
|
return title;
|
|
@@ -313,7 +292,7 @@ export function onPopState(event) {
|
|
|
313
292
|
|
|
314
293
|
/**
|
|
315
294
|
* @param {Element} dialogElement
|
|
316
|
-
* @param {(DocumentFragment|string)} [content]
|
|
295
|
+
* @param {(DocumentFragment|string|null)} [content]
|
|
317
296
|
* @return {void}
|
|
318
297
|
*/
|
|
319
298
|
export function updateTitle(dialogElement, content) {
|
|
@@ -323,14 +302,14 @@ export function updateTitle(dialogElement, content) {
|
|
|
323
302
|
// Nothing to be done
|
|
324
303
|
return;
|
|
325
304
|
}
|
|
326
|
-
title.
|
|
305
|
+
title.remove();
|
|
327
306
|
return;
|
|
328
307
|
}
|
|
329
308
|
if (!title) {
|
|
330
309
|
title = document.createElement('div');
|
|
331
310
|
title.className = 'mdw-dialog__title';
|
|
332
311
|
const popup = dialogElement.getElementsByClassName('mdw-dialog__popup')[0];
|
|
333
|
-
popup.
|
|
312
|
+
popup.prepend(title);
|
|
334
313
|
}
|
|
335
314
|
if (content instanceof DocumentFragment) {
|
|
336
315
|
while (title.lastChild) {
|
|
@@ -349,9 +328,9 @@ export function updateTitle(dialogElement, content) {
|
|
|
349
328
|
*/
|
|
350
329
|
export function updateButtonText(dialogElement, texts) {
|
|
351
330
|
const buttons = dialogElement.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
352
|
-
|
|
353
|
-
setTextNode(
|
|
354
|
-
}
|
|
331
|
+
for (let i = 0; i < buttons.length; i++) {
|
|
332
|
+
setTextNode(buttons.item(i), texts[i]);
|
|
333
|
+
}
|
|
355
334
|
}
|
|
356
335
|
|
|
357
336
|
/**
|
|
@@ -366,7 +345,7 @@ export function updateBody(dialogElement, content) {
|
|
|
366
345
|
// Nothing to be done
|
|
367
346
|
return;
|
|
368
347
|
}
|
|
369
|
-
body.
|
|
348
|
+
body.remove();
|
|
370
349
|
return;
|
|
371
350
|
}
|
|
372
351
|
if (!body) {
|
|
@@ -375,10 +354,10 @@ export function updateBody(dialogElement, content) {
|
|
|
375
354
|
body.setAttribute('mdw-ink', 'medium');
|
|
376
355
|
const title = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
377
356
|
if (title) {
|
|
378
|
-
title.
|
|
357
|
+
title.after(body);
|
|
379
358
|
} else {
|
|
380
359
|
const popup = dialogElement.getElementsByClassName('mdw-dialog__popup')[0];
|
|
381
|
-
popup.
|
|
360
|
+
popup.prepend(body);
|
|
382
361
|
}
|
|
383
362
|
}
|
|
384
363
|
if (content instanceof DocumentFragment) {
|
|
@@ -393,12 +372,11 @@ export function updateBody(dialogElement, content) {
|
|
|
393
372
|
|
|
394
373
|
/**
|
|
395
374
|
* @param {Element} dialogElement
|
|
396
|
-
* @param {Event} [event]
|
|
375
|
+
* @param {Event|MouseEvent} [event]
|
|
397
376
|
* @return {void}
|
|
398
377
|
*/
|
|
399
378
|
export function updateTransformOrigin(dialogElement, event) {
|
|
400
|
-
/** @type {HTMLElement} */
|
|
401
|
-
const popup = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
379
|
+
const popup = /** @type {HTMLElement} */ (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
402
380
|
popup.style.removeProperty('transform-origin');
|
|
403
381
|
if (!event) {
|
|
404
382
|
return;
|
|
@@ -411,13 +389,11 @@ export function updateTransformOrigin(dialogElement, event) {
|
|
|
411
389
|
let pageY;
|
|
412
390
|
const dialogRect = dialogElement.getBoundingClientRect();
|
|
413
391
|
if ('pageX' in event && 'pageY' in event) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
pageY -= window.pageYOffset;
|
|
392
|
+
pageX = event.pageX - window.pageXOffset;
|
|
393
|
+
pageY = event.pageY - window.pageYOffset;
|
|
417
394
|
} else {
|
|
418
|
-
/** @type {Element} */
|
|
419
395
|
const target = (event.target || event.currentTarget);
|
|
420
|
-
if (target instanceof Element
|
|
396
|
+
if (!(target instanceof Element)) {
|
|
421
397
|
return;
|
|
422
398
|
}
|
|
423
399
|
const rect = target.getBoundingClientRect();
|
|
@@ -448,7 +424,7 @@ export function attach(element) {
|
|
|
448
424
|
dialogCloser = document.createElement('div');
|
|
449
425
|
dialogCloser.className = 'mdw-dialog__close';
|
|
450
426
|
if (element.firstChild) {
|
|
451
|
-
element.
|
|
427
|
+
element.prepend(dialogCloser);
|
|
452
428
|
} else {
|
|
453
429
|
element.appendChild(dialogCloser);
|
|
454
430
|
}
|
|
@@ -459,24 +435,24 @@ export function attach(element) {
|
|
|
459
435
|
const buttons = popup.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
460
436
|
let foundConfirmButton = false;
|
|
461
437
|
let foundCancelButton = false;
|
|
462
|
-
|
|
438
|
+
for (const button of buttons) {
|
|
463
439
|
Button.attach(button);
|
|
464
440
|
if (button.hasAttribute('mdw-custom')) {
|
|
465
441
|
button.addEventListener('click', onCustomButtonClick);
|
|
466
|
-
|
|
442
|
+
continue;
|
|
467
443
|
}
|
|
468
444
|
if (!foundConfirmButton) {
|
|
469
445
|
button.addEventListener('click', onConfirmClick);
|
|
470
446
|
foundConfirmButton = true;
|
|
471
|
-
|
|
447
|
+
continue;
|
|
472
448
|
}
|
|
473
449
|
if (!foundCancelButton) {
|
|
474
450
|
button.addEventListener('click', onCancelClick);
|
|
475
451
|
foundCancelButton = true;
|
|
476
|
-
|
|
452
|
+
continue;
|
|
477
453
|
}
|
|
478
454
|
button.addEventListener('click', onCustomButtonClick);
|
|
479
|
-
}
|
|
455
|
+
}
|
|
480
456
|
setupARIA(element);
|
|
481
457
|
}
|
|
482
458
|
|
|
@@ -507,7 +483,7 @@ export function create(options) {
|
|
|
507
483
|
const buttonArea = document.createElement('div');
|
|
508
484
|
buttonArea.className = 'mdw-dialog__button-area';
|
|
509
485
|
let index = 0;
|
|
510
|
-
options.buttons
|
|
486
|
+
for (const buttonText of options.buttons) {
|
|
511
487
|
const button = document.createElement('div');
|
|
512
488
|
button.className = 'mdw-button mdw-theme';
|
|
513
489
|
button.setAttribute('tabindex', '0');
|
|
@@ -522,7 +498,7 @@ export function create(options) {
|
|
|
522
498
|
button.setAttribute('mdw-autofocus', '');
|
|
523
499
|
}
|
|
524
500
|
index += 1;
|
|
525
|
-
}
|
|
501
|
+
}
|
|
526
502
|
if (options.stacked) {
|
|
527
503
|
buttonArea.setAttribute('mdw-stacked', '');
|
|
528
504
|
}
|
|
@@ -549,8 +525,7 @@ export function show(dialogElement, event) {
|
|
|
549
525
|
|
|
550
526
|
if (dialogElement.getAttribute('aria-hidden') !== 'false') {
|
|
551
527
|
dialogElement.setAttribute('aria-hidden', 'false');
|
|
552
|
-
/** @type {HTMLElement} */
|
|
553
|
-
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
528
|
+
const popupElement = /** @type {HTMLElement} */ (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
554
529
|
popupElement.style.setProperty('display', 'flex');
|
|
555
530
|
changed = true;
|
|
556
531
|
}
|
|
@@ -562,13 +537,13 @@ export function show(dialogElement, event) {
|
|
|
562
537
|
}
|
|
563
538
|
attach(dialogElement);
|
|
564
539
|
const previousFocus = document.activeElement;
|
|
565
|
-
const newState = { hash: Math.random().toString(36).
|
|
540
|
+
const newState = { hash: Math.random().toString(36).slice(2, 18) };
|
|
566
541
|
let previousState = null;
|
|
567
542
|
if (window.history && window.history.pushState) {
|
|
568
543
|
if (!window.history.state) {
|
|
569
544
|
// Create new previous state
|
|
570
545
|
window.history.replaceState({
|
|
571
|
-
hash: Math.random().toString(36).
|
|
546
|
+
hash: Math.random().toString(36).slice(2, 18),
|
|
572
547
|
}, document.title);
|
|
573
548
|
}
|
|
574
549
|
previousState = window.history.state;
|
|
@@ -588,7 +563,7 @@ export function show(dialogElement, event) {
|
|
|
588
563
|
} else if (dialogElement instanceof HTMLElement) {
|
|
589
564
|
dialogElement.focus();
|
|
590
565
|
}
|
|
591
|
-
} catch
|
|
566
|
+
} catch {
|
|
592
567
|
// Failed to focus
|
|
593
568
|
}
|
|
594
569
|
return true;
|
|
@@ -605,8 +580,7 @@ export function detach(dialogElement) {
|
|
|
605
580
|
if (dialogCloser) {
|
|
606
581
|
dialogCloser.removeEventListener('click', onCancelClick);
|
|
607
582
|
}
|
|
608
|
-
/** @type {HTMLElement} */
|
|
609
|
-
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
583
|
+
const popupElement = /** @type {HTMLElement} */ (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
610
584
|
if (popupElement) {
|
|
611
585
|
popupElement.removeEventListener('keydown', onKeyDown);
|
|
612
586
|
popupElement.style.removeProperty('transform-origin');
|
|
@@ -615,12 +589,12 @@ export function detach(dialogElement) {
|
|
|
615
589
|
}
|
|
616
590
|
}
|
|
617
591
|
const buttons = popupElement.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
618
|
-
|
|
592
|
+
for (const button of buttons) {
|
|
619
593
|
Button.detach(button);
|
|
620
594
|
button.removeEventListener('click', onConfirmClick);
|
|
621
595
|
button.removeEventListener('click', onCancelClick);
|
|
622
596
|
button.removeEventListener('click', onCustomButtonClick);
|
|
623
|
-
}
|
|
597
|
+
}
|
|
624
598
|
}
|
|
625
599
|
|
|
626
600
|
// Aliases
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
@use '../../core/_length.scss' as *;
|
|
2
2
|
|
|
3
3
|
.mdw-divider {
|
|
4
|
-
|
|
5
|
-
margin-
|
|
6
|
-
border-
|
|
7
|
-
}
|
|
4
|
+
inline-size: 100%;
|
|
5
|
+
margin-block-start: -1px;
|
|
6
|
+
border-block-end: 1px solid;
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
border-left: dp(1) solid;
|
|
8
|
+
&[mdw-vertical] {
|
|
9
|
+
writing-mode: vertical-lr;
|
|
10
|
+
}
|
|
13
11
|
}
|