@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
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
dispatchDomEvent,
|
|
6
|
-
findElementParentByClassName,
|
|
7
|
-
nextTick,
|
|
8
6
|
setTextNode,
|
|
9
7
|
} from '../../core/dom.js';
|
|
10
8
|
import * as Button from '../button/index.js';
|
|
@@ -91,7 +89,7 @@ export function handleAnimationChange(snackbarElement) {
|
|
|
91
89
|
if (autoHideString == null) {
|
|
92
90
|
return;
|
|
93
91
|
}
|
|
94
|
-
const timeInSeconds = parseFloat(autoHideString) || 4;
|
|
92
|
+
const timeInSeconds = Number.parseFloat(autoHideString) || 4;
|
|
95
93
|
if (timeInSeconds < 0) {
|
|
96
94
|
return;
|
|
97
95
|
}
|
|
@@ -113,10 +111,8 @@ export function handleAnimationChange(snackbarElement) {
|
|
|
113
111
|
show(snackbarElement);
|
|
114
112
|
return;
|
|
115
113
|
}
|
|
116
|
-
if (snackbarElement.hasAttribute('mdw-autodestroy')) {
|
|
117
|
-
|
|
118
|
-
snackbarElement.parentElement.removeChild(snackbarElement);
|
|
119
|
-
}
|
|
114
|
+
if (snackbarElement.hasAttribute('mdw-autodestroy') && snackbarElement.parentElement) {
|
|
115
|
+
snackbarElement.remove();
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
|
|
@@ -145,7 +141,7 @@ export function hide(snackbarElement) {
|
|
|
145
141
|
SNACKBAR_QUEUE.splice(SNACKBAR_QUEUE.indexOf(currentQueueItem), 1);
|
|
146
142
|
}
|
|
147
143
|
if (window.getComputedStyle(snackbarElement).animationName === 'none') {
|
|
148
|
-
|
|
144
|
+
requestAnimationFrame(() => handleAnimationChange(snackbarElement));
|
|
149
145
|
}
|
|
150
146
|
return true;
|
|
151
147
|
}
|
|
@@ -159,8 +155,7 @@ export function onKeyDown(event) {
|
|
|
159
155
|
// Allow users to close snackbar with escape, for accessibilty reasons
|
|
160
156
|
event.stopPropagation();
|
|
161
157
|
event.preventDefault();
|
|
162
|
-
/** @type {Element} */
|
|
163
|
-
const snackbarElement = (event.currentTarget);
|
|
158
|
+
const snackbarElement = /** @type {Element} */ (event.currentTarget);
|
|
164
159
|
hide(snackbarElement);
|
|
165
160
|
}
|
|
166
161
|
}
|
|
@@ -170,12 +165,11 @@ export function onKeyDown(event) {
|
|
|
170
165
|
* @return {void}
|
|
171
166
|
*/
|
|
172
167
|
export function onButtonClick(event) {
|
|
173
|
-
/** @type {HTMLElement} */
|
|
174
|
-
const buttonElement = (event.currentTarget);
|
|
168
|
+
const buttonElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
175
169
|
if (buttonElement instanceof HTMLAnchorElement) {
|
|
176
170
|
event.preventDefault();
|
|
177
171
|
}
|
|
178
|
-
const snackbarElement =
|
|
172
|
+
const snackbarElement = buttonElement.closest('.mdw-snackbar');
|
|
179
173
|
hide(snackbarElement);
|
|
180
174
|
}
|
|
181
175
|
|
|
@@ -197,11 +191,11 @@ export function update(element, options) {
|
|
|
197
191
|
let span = element.getElementsByTagName('span')[0];
|
|
198
192
|
if (span) {
|
|
199
193
|
// To trigger screen readers, we destroy and create a new span and textnode
|
|
200
|
-
span.
|
|
194
|
+
span.remove();
|
|
201
195
|
}
|
|
202
196
|
span = document.createElement('span');
|
|
203
197
|
if (element.firstChild) {
|
|
204
|
-
element.
|
|
198
|
+
element.prepend(span);
|
|
205
199
|
} else {
|
|
206
200
|
element.appendChild(span);
|
|
207
201
|
}
|
|
@@ -225,7 +219,7 @@ export function update(element, options) {
|
|
|
225
219
|
// Don't set attribute if null is passed
|
|
226
220
|
}
|
|
227
221
|
} else if (button && button.parentElement) {
|
|
228
|
-
button.
|
|
222
|
+
button.remove();
|
|
229
223
|
}
|
|
230
224
|
if (options.stacked) {
|
|
231
225
|
element.setAttribute('mdw-stacked', '');
|
|
@@ -275,13 +269,13 @@ export function detach(snackbarElement) {
|
|
|
275
269
|
button.removeEventListener('click', onButtonClick);
|
|
276
270
|
}
|
|
277
271
|
// Remove timeouts and stacks
|
|
278
|
-
SNACKBAR_QUEUE.
|
|
272
|
+
for (let i = SNACKBAR_QUEUE.length - 1; i >= 0; i--) {
|
|
273
|
+
const queue = SNACKBAR_QUEUE[i];
|
|
279
274
|
if (queue.element === snackbarElement) {
|
|
280
275
|
queue.clearHideTimeout();
|
|
281
|
-
|
|
282
|
-
SNACKBAR_QUEUE.splice(index, 1);
|
|
276
|
+
SNACKBAR_QUEUE.splice(i, 1);
|
|
283
277
|
}
|
|
284
|
-
}
|
|
278
|
+
}
|
|
285
279
|
snackbarElement.removeAttribute('mdw-js');
|
|
286
280
|
}
|
|
287
281
|
|
|
@@ -299,7 +293,7 @@ export function show(snackbarElement) {
|
|
|
299
293
|
snackbarElement.setAttribute('aria-hidden', 'false');
|
|
300
294
|
attach(snackbarElement);
|
|
301
295
|
if (window.getComputedStyle(snackbarElement).animationName === 'none') {
|
|
302
|
-
|
|
296
|
+
requestAnimationFrame(() => handleAnimationChange(snackbarElement));
|
|
303
297
|
}
|
|
304
298
|
return true;
|
|
305
299
|
}
|
|
@@ -16,7 +16,6 @@ $icon-with-label-height: 72 !default;
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
.mdw-tab__list {
|
|
19
|
-
display: flex; // IE11 doesn't support grid-auto-columns
|
|
20
19
|
display: grid;
|
|
21
20
|
position: relative;
|
|
22
21
|
flex-direction: row;
|
|
@@ -25,8 +24,6 @@ $icon-with-label-height: 72 !default;
|
|
|
25
24
|
|
|
26
25
|
justify-content: flex-start;
|
|
27
26
|
|
|
28
|
-
-ms-overflow-style: none;
|
|
29
|
-
|
|
30
27
|
overflow-x: auto;
|
|
31
28
|
overflow-y: hidden;
|
|
32
29
|
scrollbar-width: none;
|
|
@@ -41,21 +38,15 @@ $icon-with-label-height: 72 !default;
|
|
|
41
38
|
&[mdw-scrollable] {
|
|
42
39
|
display: flex;
|
|
43
40
|
overflow-x: auto;
|
|
44
|
-
|
|
41
|
+
|
|
45
42
|
box-sizing: border-box;
|
|
46
|
-
|
|
43
|
+
|
|
47
44
|
&::before,
|
|
48
45
|
&::after {
|
|
49
|
-
|
|
50
|
-
min-width: dp(52);
|
|
51
46
|
// Ensures 52dp blank space at end
|
|
52
47
|
content: '';
|
|
53
|
-
}
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
min-width: dp(90);
|
|
57
|
-
max-width: 100%;
|
|
58
|
-
flex: none;
|
|
49
|
+
min-inline-size: 52px;
|
|
59
50
|
}
|
|
60
51
|
}
|
|
61
52
|
}
|
|
@@ -69,13 +60,12 @@ $icon-with-label-height: 72 !default;
|
|
|
69
60
|
|
|
70
61
|
.mdw-tab__indicator {
|
|
71
62
|
position: absolute;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
left: 0;
|
|
63
|
+
inset-block-end: 0;
|
|
64
|
+
inset-inline: 0 auto;
|
|
75
65
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
block-size: 2px;
|
|
67
|
+
inline-size: 0;
|
|
68
|
+
inline-size: 1000px;
|
|
79
69
|
|
|
80
70
|
transition-property: none;
|
|
81
71
|
|
|
@@ -87,7 +77,7 @@ $icon-with-label-height: 72 !default;
|
|
|
87
77
|
&[mdw-animate] {
|
|
88
78
|
transition-property: transform;
|
|
89
79
|
}
|
|
90
|
-
|
|
80
|
+
|
|
91
81
|
}
|
|
92
82
|
|
|
93
83
|
.mdw-tab__item {
|
|
@@ -100,7 +90,8 @@ $icon-with-label-height: 72 !default;
|
|
|
100
90
|
overflow: hidden;
|
|
101
91
|
|
|
102
92
|
box-sizing: content-box;
|
|
103
|
-
|
|
93
|
+
|
|
94
|
+
min-block-size: 48px;
|
|
104
95
|
flex: auto;
|
|
105
96
|
|
|
106
97
|
cursor: pointer;
|
|
@@ -116,43 +107,42 @@ $icon-with-label-height: 72 !default;
|
|
|
116
107
|
|
|
117
108
|
box-shadow: none;
|
|
118
109
|
|
|
119
|
-
|
|
110
|
+
.mdw-tab__list[mdw-scrollable] > & {
|
|
111
|
+
min-inline-size: 90px;
|
|
112
|
+
max-inline-size: 100%;
|
|
113
|
+
flex: none;
|
|
114
|
+
}
|
|
120
115
|
}
|
|
121
116
|
|
|
122
117
|
.mdw-tab__icon {
|
|
123
118
|
@include type.baselineToBottom($icon-to-label-baseline);
|
|
124
|
-
margin-
|
|
125
|
-
margin-bottom: dp(-$icon-to-label-baseline);
|
|
126
|
-
|
|
127
|
-
transition-property: color;
|
|
119
|
+
margin-block: dp($icon-margin-top) dp(-$icon-to-label-baseline);
|
|
128
120
|
|
|
129
121
|
pointer-events: none;
|
|
122
|
+
|
|
123
|
+
transition-property: color;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
126
|
.mdw-tab__label {
|
|
133
127
|
@include type.addRules('button');
|
|
134
128
|
|
|
135
129
|
box-sizing: border-box;
|
|
136
|
-
margin-
|
|
137
|
-
|
|
138
|
-
padding: 0 dp(16);
|
|
139
|
-
|
|
140
|
-
transition-property: color;
|
|
130
|
+
margin-block: auto;
|
|
131
|
+
padding: 0 16px;
|
|
141
132
|
|
|
142
133
|
pointer-events: none;
|
|
143
134
|
|
|
135
|
+
transition-property: color;
|
|
136
|
+
|
|
144
137
|
text-align: center;
|
|
145
138
|
|
|
146
139
|
.mdw-tab__icon ~ & {
|
|
147
140
|
@include type.baselineToTop($icon-to-label-baseline);
|
|
148
|
-
@include type.baselineToBottom($icon-with-label-height
|
|
149
|
-
- $icon-margin-top
|
|
150
|
-
- $icon-size
|
|
151
|
-
- $icon-to-label-baseline);
|
|
141
|
+
@include type.baselineToBottom($icon-with-label-height - $icon-margin-top - $icon-size - $icon-to-label-baseline);
|
|
152
142
|
|
|
153
143
|
display: block;
|
|
154
144
|
|
|
155
|
-
min-
|
|
145
|
+
min-block-size: 0;
|
|
156
146
|
margin: 0;
|
|
157
147
|
}
|
|
158
148
|
}
|
|
@@ -168,8 +158,9 @@ $icon-with-label-height: 72 !default;
|
|
|
168
158
|
overflow-x: hidden;
|
|
169
159
|
overflow-x: scroll;
|
|
170
160
|
-webkit-overflow-scrolling: touch;
|
|
161
|
+
|
|
171
162
|
scroll-behavior: smooth;
|
|
172
|
-
|
|
163
|
+
|
|
173
164
|
// W3C standard
|
|
174
165
|
scroll-snap-type: x mandatory;
|
|
175
166
|
scrollbar-width: none;
|
|
@@ -183,12 +174,7 @@ $icon-with-label-height: 72 !default;
|
|
|
183
174
|
scroll-snap-type-x: mandatory;
|
|
184
175
|
-webkit-scroll-snap-points-x: repeat(100%);
|
|
185
176
|
scroll-snap-points-x: repeat(100%);
|
|
186
|
-
|
|
187
|
-
// Safari 9
|
|
188
|
-
|
|
189
|
-
// IE + Edge
|
|
190
|
-
-ms-scroll-snap-x: mandatory snapInterval(0%, 100%);
|
|
191
|
-
|
|
177
|
+
|
|
192
178
|
overscroll-behavior-x: none;
|
|
193
179
|
|
|
194
180
|
.mdw-tab[mdw-resize-stage] & {
|
|
@@ -203,8 +189,8 @@ $icon-with-label-height: 72 !default;
|
|
|
203
189
|
.mdw-tab__panel {
|
|
204
190
|
scroll-snap-align: center;
|
|
205
191
|
|
|
206
|
-
min-
|
|
207
|
-
max-
|
|
192
|
+
min-inline-size: 100%;
|
|
193
|
+
max-inline-size: 100%;
|
|
208
194
|
flex-shrink: 0;
|
|
209
195
|
flex-basis: 100%;
|
|
210
196
|
|
|
@@ -216,17 +202,16 @@ $icon-with-label-height: 72 !default;
|
|
|
216
202
|
visibility: hidden;
|
|
217
203
|
}
|
|
218
204
|
|
|
219
|
-
|
|
220
|
-
&[aria-expanded="
|
|
221
|
-
&[aria-expanded="true"] .mdw-tabs__panel__active-hide {
|
|
205
|
+
&[aria-expanded="false"] .mdw-tab__panel__inactive-hide,
|
|
206
|
+
&[aria-expanded="true"] .mdw-tab__panel__active-hide {
|
|
222
207
|
visibility: hidden;
|
|
223
208
|
}
|
|
224
209
|
|
|
225
|
-
&[aria-expanded="false"] .mdw-
|
|
226
|
-
&[aria-expanded="true"] .mdw-
|
|
210
|
+
&[aria-expanded="false"] .mdw-tab__panel__inactive-remove,
|
|
211
|
+
&[aria-expanded="true"] .mdw-tab__panel__active-remove {
|
|
227
212
|
display: none;
|
|
228
213
|
}
|
|
229
|
-
|
|
214
|
+
|
|
230
215
|
}
|
|
231
216
|
|
|
232
217
|
.mdw-tab__content[mdw-no-scroll] {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dispatchDomEvent,
|
|
3
|
-
getPassiveEventListenerOption,
|
|
4
3
|
isRtl,
|
|
5
|
-
iterateArrayLike,
|
|
6
|
-
iterateSomeOfArrayLike,
|
|
7
4
|
scrollToElement,
|
|
8
5
|
} from '../../core/dom.js';
|
|
9
6
|
|
|
@@ -25,6 +22,11 @@ function onKeyDown(event) {
|
|
|
25
22
|
case 'ArrowRight':
|
|
26
23
|
case 'Left':
|
|
27
24
|
case 'Right':
|
|
25
|
+
if (event.target instanceof HTMLInputElement
|
|
26
|
+
|| event.target instanceof HTMLTextAreaElement) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
event.stopPropagation();
|
|
28
30
|
event.preventDefault();
|
|
29
31
|
break;
|
|
30
32
|
default:
|
|
@@ -36,8 +38,7 @@ function onKeyDown(event) {
|
|
|
36
38
|
* @return {void}
|
|
37
39
|
*/
|
|
38
40
|
export function onTabContentScroll(event) {
|
|
39
|
-
/** @type {HTMLElement} */
|
|
40
|
-
const tabContentElement = (event.currentTarget);
|
|
41
|
+
const tabContentElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
41
42
|
const isPageRtl = isRtl();
|
|
42
43
|
const scrollPoint = tabContentElement.scrollLeft / tabContentElement.clientWidth;
|
|
43
44
|
let visibleIndex = Math.floor(scrollPoint);
|
|
@@ -45,14 +46,15 @@ export function onTabContentScroll(event) {
|
|
|
45
46
|
|
|
46
47
|
// Percentage may be incorrect due to floating point rounding errors
|
|
47
48
|
// Compare integer values provided by browser to check if within 1px
|
|
48
|
-
|
|
49
|
+
for (let i = 0; i < tabContentElement.children.length; i++) {
|
|
50
|
+
const panel = tabContentElement.children.item(i);
|
|
51
|
+
if (!(panel instanceof HTMLElement)) continue;
|
|
49
52
|
if (Math.abs(tabContentElement.scrollLeft - panel.offsetLeft) <= 1) {
|
|
50
|
-
visibleIndex =
|
|
53
|
+
visibleIndex = i;
|
|
51
54
|
visibilityPercentage = 0;
|
|
52
|
-
|
|
55
|
+
break;
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
}));
|
|
57
|
+
}
|
|
56
58
|
|
|
57
59
|
const isResting = visibilityPercentage === 0;
|
|
58
60
|
let rightPanel;
|
|
@@ -88,12 +90,13 @@ export function onTabContentScroll(event) {
|
|
|
88
90
|
selectedIndex = visibleIndex + 1;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
const leftPanel = (tabContentElement.children.item(leftPanelIndex));
|
|
93
|
+
|
|
94
|
+
const leftPanel = /** @type {HTMLElement} */ (tabContentElement.children.item(leftPanelIndex));
|
|
93
95
|
|
|
94
96
|
const currentTargetIndexString = tabContentElement.getAttribute('mdw-target-index');
|
|
95
|
-
const currentTargetIndex = currentTargetIndexString == null
|
|
96
|
-
? null
|
|
97
|
+
const currentTargetIndex = (currentTargetIndexString == null)
|
|
98
|
+
? null
|
|
99
|
+
: Number.parseInt(currentTargetIndexString, 10);
|
|
97
100
|
|
|
98
101
|
let updateSelected = false;
|
|
99
102
|
let forceSelection = false;
|
|
@@ -103,12 +106,10 @@ export function onTabContentScroll(event) {
|
|
|
103
106
|
TabPanel.setExpanded(rightPanel, rightSelected);
|
|
104
107
|
}
|
|
105
108
|
updateSelected = visibilityPercentage === 0;
|
|
106
|
-
} else if (currentTargetIndex === selectedIndex) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
tabContentElement.removeAttribute('mdw-target-index');
|
|
111
|
-
}
|
|
109
|
+
} else if (currentTargetIndex === selectedIndex && visibilityPercentage === 0) {
|
|
110
|
+
updateSelected = true;
|
|
111
|
+
forceSelection = true;
|
|
112
|
+
tabContentElement.removeAttribute('mdw-target-index');
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
TabPanel.setHidden(leftPanel, false);
|
|
@@ -145,15 +146,15 @@ export function selectPanel(tabContentElement, panel, scrollToPanel = 'smooth')
|
|
|
145
146
|
let panelIndex = null;
|
|
146
147
|
/** @type {Element[]} */
|
|
147
148
|
const otherPanels = [];
|
|
148
|
-
|
|
149
|
+
// eslint-disable-next-line github/array-foreach
|
|
150
|
+
[...tabContentElement.getElementsByClassName('mdw-tab__panel')].forEach((el, index) => {
|
|
149
151
|
if (currentSelectedIndex == null && TabPanel.isExpanded(el)) {
|
|
150
152
|
currentSelectedIndex = index;
|
|
151
153
|
}
|
|
152
154
|
if (panel === el || panel === index) {
|
|
153
155
|
TabPanel.setExpanded(el, true);
|
|
154
156
|
TabPanel.setHidden(el, false);
|
|
155
|
-
/** @type {HTMLElement} */
|
|
156
|
-
panelElement = (el);
|
|
157
|
+
panelElement = /** @type {HTMLElement} */ (el);
|
|
157
158
|
panelIndex = index;
|
|
158
159
|
} else {
|
|
159
160
|
otherPanels.push(el);
|
|
@@ -163,7 +164,7 @@ export function selectPanel(tabContentElement, panel, scrollToPanel = 'smooth')
|
|
|
163
164
|
// Invalid index or panel not in tabcontent
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
for (const sibling of otherPanels) TabPanel.setExpanded(sibling, false);
|
|
167
168
|
|
|
168
169
|
const isPageRtl = isRtl();
|
|
169
170
|
const targetScrollLeft = isPageRtl
|
|
@@ -171,7 +172,7 @@ export function selectPanel(tabContentElement, panel, scrollToPanel = 'smooth')
|
|
|
171
172
|
: panelElement.offsetLeft;
|
|
172
173
|
if (!scrollToPanel || panelElement.parentElement.scrollLeft === targetScrollLeft) {
|
|
173
174
|
// No scrolling, hide others
|
|
174
|
-
|
|
175
|
+
for (const sibling of otherPanels) TabPanel.setHidden(sibling, true);
|
|
175
176
|
return;
|
|
176
177
|
}
|
|
177
178
|
if (scrollToPanel && panelElement) {
|
|
@@ -189,8 +190,10 @@ export function selectPanel(tabContentElement, panel, scrollToPanel = 'smooth')
|
|
|
189
190
|
* @return {void}
|
|
190
191
|
*/
|
|
191
192
|
export function attach(tabContentElement) {
|
|
192
|
-
tabContentElement.addEventListener('scroll', onTabContentScroll,
|
|
193
|
-
|
|
193
|
+
tabContentElement.addEventListener('scroll', onTabContentScroll, { passive: true });
|
|
194
|
+
for (const element of tabContentElement.getElementsByClassName('mdw-tab__panel')) {
|
|
195
|
+
TabPanel.attach(element);
|
|
196
|
+
}
|
|
194
197
|
tabContentElement.addEventListener('keydown', onKeyDown);
|
|
195
198
|
}
|
|
196
199
|
|
|
@@ -201,5 +204,7 @@ export function attach(tabContentElement) {
|
|
|
201
204
|
export function detach(tabContentElement) {
|
|
202
205
|
tabContentElement.removeEventListener('keydown', onKeyDown);
|
|
203
206
|
tabContentElement.removeEventListener('scroll', onTabContentScroll);
|
|
204
|
-
|
|
207
|
+
for (const element of tabContentElement.getElementsByClassName('mdw-tab__panel')) {
|
|
208
|
+
TabPanel.detach(element);
|
|
209
|
+
}
|
|
205
210
|
}
|
package/components/tab/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dispatchDomEvent,
|
|
3
|
-
getPassiveEventListenerOption,
|
|
4
|
-
iterateSomeOfArrayLike,
|
|
5
|
-
nextTick,
|
|
6
3
|
} from '../../core/dom.js';
|
|
7
4
|
|
|
8
5
|
import * as TabContent from './content.js';
|
|
@@ -35,8 +32,7 @@ export function onResize(tabElement) {
|
|
|
35
32
|
stage += 1;
|
|
36
33
|
tabElement.setAttribute('mdw-resize-stage', stage.toString());
|
|
37
34
|
if (stage === RESIZE_WAIT_FRAMES) {
|
|
38
|
-
/** @type {HTMLElement} */
|
|
39
|
-
const tabContentElement = (tabElement.getElementsByClassName('mdw-tab__content')[0]);
|
|
35
|
+
const tabContentElement = /** @type {HTMLElement} */ (tabElement.getElementsByClassName('mdw-tab__content')[0]);
|
|
40
36
|
if (tabContentElement) {
|
|
41
37
|
/** @type {HTMLElement} */
|
|
42
38
|
const relatedPanel = (tabContentElement.querySelector('.mdw-tab__panel[aria-expanded="true"]'));
|
|
@@ -45,8 +41,7 @@ export function onResize(tabElement) {
|
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
} else if (stage === RESIZE_WAIT_FRAMES * 2) {
|
|
48
|
-
/** @type {HTMLElement} */
|
|
49
|
-
const tabListElement = (tabElement.getElementsByClassName('mdw-tab__list')[0]);
|
|
44
|
+
const tabListElement = /** @type {HTMLElement} */ (tabElement.getElementsByClassName('mdw-tab__list')[0]);
|
|
50
45
|
if (tabListElement) {
|
|
51
46
|
/** @type {HTMLElement} */
|
|
52
47
|
const relatedItem = (tabListElement.querySelector('.mdw-tab__item[aria-selected="true"]'));
|
|
@@ -58,9 +53,9 @@ export function onResize(tabElement) {
|
|
|
58
53
|
return;
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
|
|
56
|
+
requestAnimationFrame(performResize);
|
|
62
57
|
}
|
|
63
|
-
|
|
58
|
+
requestAnimationFrame(performResize);
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
/**
|
|
@@ -85,18 +80,14 @@ export function onTabItemSelectedChange(event) {
|
|
|
85
80
|
if (event.detail.value !== 'true') {
|
|
86
81
|
return;
|
|
87
82
|
}
|
|
88
|
-
/** @type {HTMLElement} */
|
|
89
|
-
const
|
|
90
|
-
/** @type {HTMLElement} */
|
|
91
|
-
const tabItemElement = (event.target);
|
|
92
|
-
/** @type {HTMLElement} */
|
|
93
|
-
const tabListElement = (tabElement.getElementsByClassName('mdw-tab__list')[0]);
|
|
83
|
+
const tabElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
84
|
+
const tabItemElement = /** @type {HTMLElement} */ (event.target);
|
|
85
|
+
const tabListElement = /** @type {HTMLElement} */ (tabElement.getElementsByClassName('mdw-tab__list')[0]);
|
|
94
86
|
if (!tabListElement) {
|
|
95
87
|
return;
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
/** @type {HTMLElement} */
|
|
99
|
-
const tabContentElement = (tabElement.getElementsByClassName('mdw-tab__content')[0]);
|
|
90
|
+
const tabContentElement = /** @type {HTMLElement} */ (tabElement.getElementsByClassName('mdw-tab__content')[0]);
|
|
100
91
|
const tabItemIndex = TabList.getTabItemIndex(tabListElement, tabItemElement);
|
|
101
92
|
if (tabItemIndex === -1) {
|
|
102
93
|
return;
|
|
@@ -120,8 +111,7 @@ export function onTabItemSelectedChange(event) {
|
|
|
120
111
|
* @return {void}
|
|
121
112
|
*/
|
|
122
113
|
export function onTabContentScroll(event) {
|
|
123
|
-
/** @type {HTMLElement} */
|
|
124
|
-
const tabElement = (event.currentTarget);
|
|
114
|
+
const tabElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
125
115
|
const { detail } = event;
|
|
126
116
|
if (!detail.forceSelection && tabElement.hasAttribute('mdw-resize-stage')) {
|
|
127
117
|
return;
|
|
@@ -147,14 +137,12 @@ export function onTabPanelExpandedChange(event) {
|
|
|
147
137
|
if (event.detail.value !== 'true') {
|
|
148
138
|
return;
|
|
149
139
|
}
|
|
150
|
-
/** @type {HTMLElement} */
|
|
151
|
-
const tabElement = (event.currentTarget);
|
|
140
|
+
const tabElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
152
141
|
if (tabElement.hasAttribute('mdw-resize-stage')) {
|
|
153
142
|
return;
|
|
154
143
|
}
|
|
155
144
|
let index = 0;
|
|
156
|
-
/** @type {HTMLElement} */
|
|
157
|
-
const tabPanelElement = (event.target);
|
|
145
|
+
const tabPanelElement = /** @type {HTMLElement} */ (event.target);
|
|
158
146
|
let sibling = tabPanelElement.previousElementSibling;
|
|
159
147
|
while (sibling) {
|
|
160
148
|
index += 1;
|
|
@@ -181,22 +169,31 @@ export function attach(tabElement) {
|
|
|
181
169
|
TabContent.attach(tabContentElement);
|
|
182
170
|
}
|
|
183
171
|
|
|
184
|
-
tabElement.addEventListener(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
172
|
+
tabElement.addEventListener(
|
|
173
|
+
TabContent.SCROLL_EVENT,
|
|
174
|
+
onTabContentScroll,
|
|
175
|
+
{ passive: true },
|
|
176
|
+
);
|
|
177
|
+
tabElement.addEventListener(
|
|
178
|
+
TabItem.SELECTED_CHANGE_EVENT,
|
|
179
|
+
onTabItemSelectedChange,
|
|
180
|
+
{ passive: true },
|
|
181
|
+
);
|
|
182
|
+
tabElement.addEventListener(
|
|
183
|
+
TabPanel.EXPANDED_CHANGE_EVENT,
|
|
184
|
+
onTabPanelExpandedChange,
|
|
185
|
+
{ passive: true },
|
|
186
|
+
);
|
|
190
187
|
|
|
191
|
-
/** @type {
|
|
188
|
+
/** @type {HTMLCollectionOf<Element>|Element[]} */
|
|
192
189
|
const items = (tabListElement && tabListElement.getElementsByClassName('mdw-tab__item')) || [];
|
|
193
|
-
/** @type {
|
|
190
|
+
/** @type {HTMLCollectionOf<Element>|Element[]} */
|
|
194
191
|
const panels = (tabContentElement && tabContentElement.getElementsByClassName('mdw-tab__panel')) || [];
|
|
195
192
|
|
|
196
193
|
let selectedItem;
|
|
197
194
|
let selectedPanel;
|
|
198
195
|
let selectedIndex;
|
|
199
|
-
|
|
196
|
+
[...items].some((itemElement, index) => {
|
|
200
197
|
if (itemElement.getAttribute('aria-selected') === 'true') {
|
|
201
198
|
selectedItem = itemElement;
|
|
202
199
|
selectedPanel = panels[index];
|
|
@@ -206,7 +203,7 @@ export function attach(tabElement) {
|
|
|
206
203
|
return false;
|
|
207
204
|
});
|
|
208
205
|
if (selectedIndex == null) {
|
|
209
|
-
|
|
206
|
+
[...panels].some((panelElement, index) => {
|
|
210
207
|
if (panelElement.getAttribute('aria-expanded') === 'true') {
|
|
211
208
|
selectedPanel = panelElement;
|
|
212
209
|
selectedItem = items[index];
|
package/components/tab/item.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// https://www.w3.org/TR/wai-aria-1.1/#tab
|
|
2
2
|
|
|
3
3
|
import * as AriaTab from '../../core/aria/tab.js';
|
|
4
|
-
import { iterateArrayLike } from '../../core/dom.js';
|
|
5
4
|
import * as Overlay from '../../core/overlay/index.js';
|
|
6
5
|
import * as Ripple from '../../core/ripple/index.js';
|
|
7
6
|
|
|
@@ -22,8 +21,7 @@ export function setSelected(element, value, dispatchEvent = true) {
|
|
|
22
21
|
* @return {void}
|
|
23
22
|
*/
|
|
24
23
|
function onClick(event) {
|
|
25
|
-
/** @type {HTMLElement} */
|
|
26
|
-
const element = (event.currentTarget);
|
|
24
|
+
const element = /** @type {HTMLElement} */ (event.currentTarget);
|
|
27
25
|
if (element.getAttribute('aria-disabled') === 'true') {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
@@ -36,8 +34,9 @@ function onClick(event) {
|
|
|
36
34
|
*/
|
|
37
35
|
export function attachAria(element) {
|
|
38
36
|
AriaTab.attach(element);
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
for (const el of element.getElementsByClassName('mdw-tab__icon')) {
|
|
38
|
+
el.setAttribute('aria-hidden', 'true');
|
|
39
|
+
}
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
/**
|