@shortfuse/materialdesignweb 0.2.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 +188 -30
- package/.stylelintrc.json +643 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +36 -0
- package/README.md +82 -2
- package/adapters/datatable/column.js +176 -0
- package/adapters/datatable/index.js +253 -437
- package/adapters/dom/index.js +586 -0
- package/adapters/list/index.js +36 -113
- package/adapters/search/index.js +153 -180
- package/components/appbar/_spec.scss +165 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +83 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +4 -4
- package/components/bottomnav/_spec.scss +149 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +100 -120
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +88 -0
- package/components/button/README.md +16 -22
- package/components/button/_spec.scss +162 -0
- package/components/button/_theme.scss +42 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +37 -48
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +241 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +111 -0
- package/components/chip/_theme.scss +105 -0
- package/components/chip/index.js +23 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +225 -0
- package/components/datatable/_theme.scss +128 -0
- package/components/datatable/cell.js +44 -0
- package/components/datatable/columnheader.js +46 -0
- package/components/datatable/index.js +339 -443
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +48 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +203 -0
- package/components/dialog/_theme.scss +7 -0
- package/components/dialog/index.js +512 -437
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +11 -0
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +2 -0
- package/components/elevation/_spec.scss +9 -0
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +2 -0
- package/components/fab/{style.scss → _spec.scss} +104 -79
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +85 -79
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +169 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +11 -0
- package/components/layout/_spec.scss +916 -0
- package/components/layout/_theme.scss +19 -0
- package/components/layout/index.js +454 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +363 -0
- package/components/list/_theme.scss +102 -0
- package/components/list/content.js +106 -0
- package/components/list/index.js +234 -79
- package/components/list/index.scss +2 -0
- package/components/list/item.js +167 -0
- package/components/list/secondary.js +45 -0
- package/components/menu/_spec.scss +329 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +636 -651
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +231 -0
- package/components/progress/_spec.scss +156 -0
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +29 -13
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +376 -0
- package/components/selection/_theme.scss +134 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +70 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +54 -0
- package/components/selection/radiogroup.js +40 -0
- package/components/slider/{style.scss → _spec.scss} +31 -34
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +150 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +293 -206
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +220 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +210 -0
- package/components/tab/index.js +229 -213
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +88 -0
- package/components/tab/list.js +196 -0
- package/components/tab/panel.js +54 -0
- package/components/textfield/README.md +4 -4
- package/components/textfield/_spec.scss +763 -0
- package/components/textfield/_theme.scss +264 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +132 -138
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +185 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +227 -0
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +2 -0
- package/core/_breakpoint.scss +189 -0
- package/core/_elevation.scss +78 -0
- package/core/_length.scss +8 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +12 -0
- package/core/_type.scss +128 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +49 -0
- package/core/aria/keyboard.js +92 -0
- package/core/aria/rovingtabindex.js +175 -0
- package/core/aria/tab.js +59 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +180 -0
- package/core/overlay/_spec.scss +28 -0
- package/core/overlay/_theme.scss +147 -0
- package/core/overlay/index.js +95 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +196 -0
- package/core/ripple/_theme.scss +20 -0
- package/core/ripple/index.js +286 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_aliases.scss +15 -0
- package/core/theme/_config.scss +8 -0
- package/core/theme/_functions.scss +22 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -151
- package/core/theme/_spec.scss +0 -0
- package/core/theme/_theme.scss +268 -0
- package/core/theme/index.js +50 -0
- package/core/theme/index.scss +4 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +465 -0
- package/docs/_flex.scss +28 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +27 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +146 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +88 -0
- package/docs/{src/storage.js → _storage.js} +0 -0
- package/docs/docs.scss +331 -0
- package/docs/framework.scss +26 -0
- package/docs/index.eta +12 -0
- package/docs/index.js +7 -0
- package/docs/pages/appbar.eta +108 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +118 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +175 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +80 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +261 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +160 -0
- package/docs/pages/dialog.eta +184 -0
- package/docs/{src/components → pages}/dialog.js +35 -48
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +140 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/{src/components → pages}/fab.js +6 -13
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +8 -0
- package/docs/pages/menu.eta +274 -0
- package/docs/{src/components → pages}/menu.js +26 -42
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +3 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/{src/components → pages}/progress.js +2 -4
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +3 -0
- package/docs/pages/search.eta +242 -0
- package/docs/pages/search.js +226 -0
- package/docs/pages/selection.eta +107 -0
- package/docs/pages/selection.js +12 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/{src/components → pages}/snackbar.js +31 -36
- package/docs/pages/tab.eta +407 -0
- package/docs/pages/tab.js +152 -0
- package/docs/pages/textfield.eta +487 -0
- package/docs/{src/components → pages}/textfield.js +41 -45
- package/docs/pages/tooltip.eta +92 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +52 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/postrender.js +41 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +478 -0
- package/docs/pwa/pwa.js +298 -0
- package/docs/pwa/pwa.scss +31 -0
- package/docs/themes/theme-colored.scss +15 -0
- package/docs/themes/theme-default.scss +3 -0
- package/index.scss +27 -0
- package/jsconfig.json +8 -2
- package/package.json +54 -27
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/tsconfig.json +16 -0
- package/utils/function.js +3 -0
- package/webpack.config.js +224 -68
- package/_index.scss +0 -4
- package/components/all-components.scss +0 -21
- package/components/bottomnav/style.scss +0 -190
- package/components/bottomnav/theming.scss +0 -76
- package/components/button/style.scss +0 -315
- package/components/button/theming.scss +0 -134
- package/components/card/style.scss +0 -175
- package/components/card/theming.scss +0 -43
- package/components/common/dom.js +0 -51
- package/components/common/functions.scss +0 -174
- package/components/common/mixins.scss +0 -122
- package/components/common/motion.scss +0 -36
- package/components/common/type.scss +0 -104
- package/components/common/variables.scss +0 -46
- package/components/datatable/style.scss +0 -257
- package/components/datatable/theming.scss +0 -119
- package/components/dialog/style.scss +0 -159
- package/components/dialog/theming.scss +0 -29
- package/components/divider/style.scss +0 -7
- package/components/divider/theming.scss +0 -20
- package/components/elevation/style.scss +0 -32
- package/components/layout/style.scss +0 -223
- package/components/list/style.scss +0 -358
- package/components/list/theming.scss +0 -83
- package/components/menu/style.scss +0 -280
- package/components/menu/theming.scss +0 -80
- package/components/navdrawer/index.js +0 -200
- package/components/navdrawer/style.scss +0 -595
- package/components/navdrawer/theming.scss +0 -62
- package/components/progress/style.scss +0 -136
- package/components/ripple/index.js +0 -63
- package/components/ripple/ripple.scss +0 -122
- package/components/selection/style.scss +0 -320
- package/components/selection/theming.scss +0 -98
- package/components/snackbar/style.scss +0 -212
- package/components/switch/style.scss +0 -3
- package/components/tab/style.scss +0 -275
- package/components/tab/theming.scss +0 -34
- package/components/template/theming.scss +0 -31
- package/components/textfield/style.scss +0 -795
- package/components/textfield/theming.scss +0 -256
- package/components/theming/globals.scss +0 -25
- package/components/theming/theming.scss +0 -559
- package/components/toolbar/style.scss +0 -190
- package/components/toolbar/theming.scss +0 -32
- package/components/tooltip/style.scss +0 -135
- package/components/type/style.scss +0 -167
- package/components/type/theming.scss +0 -25
- package/docs/bottomnav.html +0 -1
- package/docs/bottomnav.min.js +0 -2
- package/docs/bottomnav.min.js.map +0 -1
- package/docs/button.html +0 -1
- package/docs/button.min.js +0 -2
- package/docs/button.min.js.map +0 -1
- package/docs/card.html +0 -1
- package/docs/card.min.js +0 -2
- package/docs/card.min.js.map +0 -1
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -2
- package/docs/components.min.js.map +0 -1
- package/docs/datatable.html +0 -1
- package/docs/datatable.min.js +0 -2
- package/docs/datatable.min.js.map +0 -1
- package/docs/dialog.html +0 -1
- package/docs/dialog.min.js +0 -2
- package/docs/dialog.min.js.map +0 -1
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -2
- package/docs/docs.min.js.map +0 -1
- package/docs/elevation.html +0 -1
- package/docs/elevation.min.js +0 -2
- package/docs/elevation.min.js.map +0 -1
- package/docs/fab.html +0 -1
- package/docs/fab.min.js +0 -2
- package/docs/fab.min.js.map +0 -1
- package/docs/index.html +0 -1
- package/docs/index.min.js +0 -2
- package/docs/index.min.js.map +0 -1
- package/docs/layout.html +0 -1
- package/docs/layout.min.js +0 -2
- package/docs/layout.min.js.map +0 -1
- package/docs/list.html +0 -1
- package/docs/list.min.js +0 -2
- package/docs/list.min.js.map +0 -1
- package/docs/menu.html +0 -1
- package/docs/menu.min.js +0 -2
- package/docs/menu.min.js.map +0 -1
- package/docs/navdrawer.html +0 -1
- package/docs/navdrawer.min.js +0 -2
- package/docs/navdrawer.min.js.map +0 -1
- package/docs/prerender.min.js +0 -2
- package/docs/prerender.min.js.map +0 -1
- package/docs/progress.html +0 -1
- package/docs/progress.min.js +0 -2
- package/docs/progress.min.js.map +0 -1
- package/docs/search.html +0 -1
- package/docs/search.min.js +0 -2
- package/docs/search.min.js.map +0 -1
- package/docs/selection.html +0 -1
- package/docs/selection.min.js +0 -2
- package/docs/selection.min.js.map +0 -1
- package/docs/slider.html +0 -1
- package/docs/slider.min.js +0 -2
- package/docs/slider.min.js.map +0 -1
- package/docs/snackbar.html +0 -1
- package/docs/snackbar.min.js +0 -2
- package/docs/snackbar.min.js.map +0 -1
- package/docs/src/components/bottomnav.js +0 -16
- package/docs/src/components/bottomnav.pug +0 -112
- package/docs/src/components/button.js +0 -156
- package/docs/src/components/button.pug +0 -194
- package/docs/src/components/card.js +0 -136
- package/docs/src/components/card.pug +0 -133
- package/docs/src/components/datatable.js +0 -183
- package/docs/src/components/datatable.pug +0 -324
- package/docs/src/components/dialog.pug +0 -138
- package/docs/src/components/elevation.js +0 -3
- package/docs/src/components/elevation.pug +0 -17
- package/docs/src/components/fab.pug +0 -84
- package/docs/src/components/layout.js +0 -116
- package/docs/src/components/layout.pug +0 -104
- package/docs/src/components/list.js +0 -15
- package/docs/src/components/list.pug +0 -293
- package/docs/src/components/menu.pug +0 -292
- package/docs/src/components/navdrawer.js +0 -112
- package/docs/src/components/navdrawer.pug +0 -113
- package/docs/src/components/progress.pug +0 -17
- package/docs/src/components/search.js +0 -206
- package/docs/src/components/search.pug +0 -149
- package/docs/src/components/selection.js +0 -6
- package/docs/src/components/selection.pug +0 -116
- package/docs/src/components/slider.js +0 -3
- package/docs/src/components/slider.pug +0 -19
- package/docs/src/components/snackbar.pug +0 -145
- package/docs/src/components/tab.js +0 -137
- package/docs/src/components/tab.pug +0 -329
- package/docs/src/components/textfield.pug +0 -416
- package/docs/src/components/toolbar.js +0 -6
- package/docs/src/components/toolbar.pug +0 -86
- package/docs/src/components/tooltip.js +0 -6
- package/docs/src/components/tooltip.pug +0 -76
- package/docs/src/components/type.js +0 -6
- package/docs/src/components/type.pug +0 -34
- package/docs/src/components.scss +0 -1
- package/docs/src/docs.scss +0 -284
- package/docs/src/index.js +0 -3
- package/docs/src/index.pug +0 -6
- package/docs/src/menuoptions.js +0 -136
- package/docs/src/mixins.pug +0 -139
- package/docs/src/prerender.js +0 -26
- package/docs/src/sample-utils.js +0 -108
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -18
- package/docs/src/theming.scss +0 -18
- package/docs/tab.html +0 -1
- package/docs/tab.min.js +0 -2
- package/docs/tab.min.js.map +0 -1
- package/docs/textfield.html +0 -2
- package/docs/textfield.min.js +0 -2
- package/docs/textfield.min.js.map +0 -1
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -2
- package/docs/theming.ie11.min.js.map +0 -1
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -2
- package/docs/theming.min.js.map +0 -1
- package/docs/toolbar.html +0 -1
- package/docs/toolbar.min.js +0 -2
- package/docs/toolbar.min.js.map +0 -1
- package/docs/tooltip.html +0 -1
- package/docs/tooltip.min.js +0 -2
- package/docs/tooltip.min.js.map +0 -1
- package/docs/type.html +0 -1
- package/docs/type.min.js +0 -2
- package/docs/type.min.js.map +0 -1
- package/index.js +0 -16
package/components/list/index.js
CHANGED
|
@@ -1,101 +1,256 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#Listbox
|
|
2
|
+
// https://www.w3.org/TR/wai-aria-practices/#TreeView
|
|
3
|
+
// https://www.w3.org/TR/wai-aria-practices/examples/landmarks/navigation.html
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import * as Attributes from '../../core/aria/attributes.js';
|
|
6
|
+
import * as Keyboard from '../../core/aria/keyboard.js';
|
|
7
|
+
import * as RovingTabIndex from '../../core/aria/rovingtabindex.js';
|
|
8
|
+
|
|
9
|
+
import * as ListContent from './content.js';
|
|
10
|
+
import * as ListItem from './item.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Event} event
|
|
14
|
+
* @return {void}
|
|
15
|
+
*/
|
|
16
|
+
function onContentFocusEvent(event) {
|
|
17
|
+
const listElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
18
|
+
const onFocusInteraction = listElement.getAttribute('mdw-on-focus');
|
|
19
|
+
if (!onFocusInteraction) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const listContentElement = /** @type {HTMLElement} */ (event.target);
|
|
23
|
+
if (Attributes.isDisabled(listContentElement)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const interaction of onFocusInteraction.split(' ')) {
|
|
27
|
+
switch (interaction) {
|
|
28
|
+
case 'select':
|
|
29
|
+
ListContent.setSelected(listContentElement, true);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
}
|
|
12
33
|
}
|
|
34
|
+
}
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @param {CustomEvent} event
|
|
38
|
+
* @return {void}
|
|
39
|
+
*/
|
|
40
|
+
function onSelectedChangeEvent(event) {
|
|
41
|
+
const listElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
42
|
+
// List is readonly
|
|
43
|
+
if (listElement.getAttribute('aria-readonly') === 'true') {
|
|
44
|
+
event.stopPropagation();
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const listElementRole = listElement.getAttribute('role');
|
|
49
|
+
if (listElementRole !== 'listbox' && listElementRole !== 'tree') {
|
|
50
|
+
// Bubble up
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (event.detail.value === 'false') {
|
|
54
|
+
// Item is radio-like and cannot be unselected
|
|
55
|
+
if (listElement.getAttribute('aria-required') === 'true'
|
|
56
|
+
&& listElement.getAttribute('aria-multiselectable') !== 'true') {
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const itemElement = /** @type {HTMLElement} */ (event.target);
|
|
63
|
+
if (listElement.getAttribute('aria-multiselectable') !== 'true') {
|
|
64
|
+
// Item is radio-like and must uncheck others
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
// Wait to see if event is cancelled
|
|
67
|
+
if (event.defaultPrevented) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const role = itemElement.getAttribute('role');
|
|
71
|
+
for (const item of listElement.querySelectorAll(`[role="${role}"][aria-selected="true"]`)) {
|
|
72
|
+
if (item !== itemElement) {
|
|
73
|
+
item.setAttribute('aria-selected', 'false');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
21
77
|
}
|
|
78
|
+
}
|
|
22
79
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @param {Event} event
|
|
82
|
+
* @return {void}
|
|
83
|
+
*/
|
|
84
|
+
function onTabIndexZeroed(event) {
|
|
85
|
+
event.stopPropagation();
|
|
86
|
+
const listElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
87
|
+
const currentItem = /** @type {HTMLElement} */ (event.target);
|
|
88
|
+
switch (listElement.getAttribute('role')) {
|
|
89
|
+
case 'tree':
|
|
90
|
+
RovingTabIndex.removeTabIndex(listElement.querySelectorAll('[role="treeitem"]'), [currentItem]);
|
|
91
|
+
break;
|
|
92
|
+
case 'listbox':
|
|
93
|
+
RovingTabIndex.removeTabIndex(listElement.querySelectorAll('[role="option"]'), [currentItem]);
|
|
94
|
+
break;
|
|
95
|
+
case 'radiogroup':
|
|
96
|
+
RovingTabIndex.removeTabIndex(listElement.querySelectorAll('[role="radio"]'), [currentItem]);
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @param {CustomEvent} event
|
|
103
|
+
* @return {void}
|
|
104
|
+
*/
|
|
105
|
+
function onDownArrowKey(event) {
|
|
106
|
+
if (event.detail.ctrlKey || event.detail.altKey
|
|
107
|
+
|| event.detail.shiftKey || event.detail.metaKey) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
const listElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
113
|
+
switch (listElement.getAttribute('role')) {
|
|
114
|
+
case 'tree':
|
|
115
|
+
RovingTabIndex.selectNext(listElement.querySelectorAll('[role="treeitem"]'));
|
|
116
|
+
break;
|
|
117
|
+
case 'listbox':
|
|
118
|
+
RovingTabIndex.selectNext(listElement.querySelectorAll('[role="option"]'));
|
|
119
|
+
break;
|
|
120
|
+
case 'radiogroup':
|
|
121
|
+
RovingTabIndex.selectNext(listElement.querySelectorAll('[role="radio"]'));
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
30
124
|
}
|
|
31
125
|
}
|
|
32
126
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
127
|
+
/**
|
|
128
|
+
* @param {CustomEvent} event
|
|
129
|
+
* @return {void}
|
|
130
|
+
*/
|
|
131
|
+
function onUpArrowKey(event) {
|
|
132
|
+
if (event.detail.ctrlKey || event.detail.altKey
|
|
133
|
+
|| event.detail.shiftKey || event.detail.metaKey) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
const listElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
139
|
+
switch (listElement.getAttribute('role')) {
|
|
140
|
+
case 'tree':
|
|
141
|
+
RovingTabIndex.selectPrevious(listElement.querySelectorAll('[role="treeitem"]'));
|
|
142
|
+
break;
|
|
143
|
+
case 'listbox':
|
|
144
|
+
RovingTabIndex.selectPrevious(listElement.querySelectorAll('[role="option"]'));
|
|
145
|
+
break;
|
|
146
|
+
case 'radiogroup':
|
|
147
|
+
RovingTabIndex.selectPrevious(listElement.querySelectorAll('[role="radio"]'));
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
43
150
|
}
|
|
151
|
+
}
|
|
44
152
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
153
|
+
/**
|
|
154
|
+
* @param {Element} listElement
|
|
155
|
+
* @param {string} role
|
|
156
|
+
* @return {void}
|
|
157
|
+
*/
|
|
158
|
+
export function setupAria(listElement, role = 'tree') {
|
|
159
|
+
if (!listElement.hasAttribute('role')) {
|
|
160
|
+
listElement.setAttribute('role', role);
|
|
50
161
|
}
|
|
162
|
+
listElement.setAttribute('aria-orientation', 'vertical');
|
|
163
|
+
if (!listElement.hasAttribute('aria-multiselectable')) {
|
|
164
|
+
listElement.setAttribute('aria-multiselectable', 'false');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
51
167
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
168
|
+
/**
|
|
169
|
+
* @param {Element} listElement
|
|
170
|
+
* @return {void}
|
|
171
|
+
*/
|
|
172
|
+
export function attach(listElement) {
|
|
173
|
+
let role = listElement.getAttribute('role');
|
|
174
|
+
if (!role) {
|
|
175
|
+
let newRole = 'listbox';
|
|
176
|
+
const parentRole = listElement.parentElement && listElement.parentElement.getAttribute('role');
|
|
177
|
+
if (parentRole === 'treeitem') {
|
|
178
|
+
newRole = 'group';
|
|
63
179
|
} else {
|
|
64
|
-
|
|
180
|
+
for (const child of listElement.children) {
|
|
181
|
+
if (child.hasAttribute('aria-expanded') && child.classList.contains('mdw-list__item')) {
|
|
182
|
+
newRole = 'tree';
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
65
186
|
}
|
|
187
|
+
listElement.setAttribute('role', newRole);
|
|
188
|
+
role = newRole;
|
|
66
189
|
}
|
|
67
|
-
}
|
|
68
190
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
static attach(listElement) {
|
|
75
|
-
const items = listElement.getElementsByClassName('mdw-list__item');
|
|
76
|
-
const expanders = listElement.getElementsByClassName('mdw-list__expander');
|
|
77
|
-
for (let i = 0; i < items.length; i += 1) {
|
|
78
|
-
ListItem.attach(items.item(i));
|
|
79
|
-
}
|
|
80
|
-
for (let i = 0; i < expanders.length; i += 1) {
|
|
81
|
-
ListExpander.attach(expanders.item(i));
|
|
191
|
+
setupAria(listElement, role);
|
|
192
|
+
for (const child of listElement.children) {
|
|
193
|
+
if (child.classList.contains('mdw-list__item')) {
|
|
194
|
+
ListItem.attach(child);
|
|
82
195
|
}
|
|
83
196
|
}
|
|
197
|
+
for (const el of listElement.getElementsByClassName('mdw-list')) {
|
|
198
|
+
attach(el);
|
|
199
|
+
}
|
|
200
|
+
if (listElement.hasAttribute('mdw-list-js')) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (role !== 'listbox' && role !== 'tree' && role !== 'radiogroup') {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
84
206
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
207
|
+
switch (role) {
|
|
208
|
+
case 'tree':
|
|
209
|
+
RovingTabIndex.setupTabIndexes(listElement.querySelectorAll('[role="treeitem"]'));
|
|
210
|
+
break;
|
|
211
|
+
case 'listbox':
|
|
212
|
+
RovingTabIndex.setupTabIndexes(listElement.querySelectorAll('[role="option"]'));
|
|
213
|
+
break;
|
|
214
|
+
case 'radiogroup':
|
|
215
|
+
RovingTabIndex.setupTabIndexes(listElement.querySelectorAll('[role="radio"]'));
|
|
216
|
+
break;
|
|
217
|
+
default:
|
|
218
|
+
return;
|
|
94
219
|
}
|
|
220
|
+
|
|
221
|
+
listElement.addEventListener(Keyboard.DOWN_ARROW_KEY, onDownArrowKey);
|
|
222
|
+
listElement.addEventListener(Keyboard.UP_ARROW_KEY, onUpArrowKey);
|
|
223
|
+
listElement.addEventListener(RovingTabIndex.TABINDEX_ZEROED, onTabIndexZeroed);
|
|
224
|
+
listElement.addEventListener(ListContent.SELECTED_CHANGE_EVENT, onSelectedChangeEvent);
|
|
225
|
+
listElement.addEventListener(ListContent.FOCUS_EVENT, onContentFocusEvent);
|
|
226
|
+
listElement.setAttribute('mdw-list-js', '');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {Element|Document} [root=document]
|
|
231
|
+
* @return {void}
|
|
232
|
+
*/
|
|
233
|
+
export function attachAll(root = document) {
|
|
234
|
+
for (const el of root.getElementsByClassName('mdw-list')) attach(el);
|
|
95
235
|
}
|
|
96
236
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
237
|
+
/**
|
|
238
|
+
* @param {Element} listElement
|
|
239
|
+
* @return {void}
|
|
240
|
+
*/
|
|
241
|
+
export function detach(listElement) {
|
|
242
|
+
for (const child of listElement.children) {
|
|
243
|
+
if (child.classList.contains('mdw-list__item')) {
|
|
244
|
+
ListItem.detach(child);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const elements = listElement.querySelectorAll(`[role="${listElement.getAttribute('role') === 'tree' ? 'treeitem' : 'option'}"]`);
|
|
248
|
+
for (const element of elements) {
|
|
249
|
+
RovingTabIndex.detach(element);
|
|
250
|
+
}
|
|
251
|
+
listElement.removeEventListener(ListContent.SELECTED_CHANGE_EVENT, onSelectedChangeEvent);
|
|
252
|
+
listElement.removeEventListener(Keyboard.DOWN_ARROW_KEY, onDownArrowKey);
|
|
253
|
+
listElement.removeEventListener(Keyboard.UP_ARROW_KEY, onUpArrowKey);
|
|
254
|
+
listElement.removeEventListener(RovingTabIndex.TABINDEX_ZEROED, onTabIndexZeroed);
|
|
255
|
+
listElement.removeAttribute('mdw-list-js');
|
|
256
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as Keyboard from '../../core/aria/keyboard.js';
|
|
2
|
+
import { getChildElementByClass } from '../../core/dom.js';
|
|
3
|
+
|
|
4
|
+
import * as ListContent from './content.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Element} listItemElement
|
|
8
|
+
* @return {boolean}
|
|
9
|
+
*/
|
|
10
|
+
export function isExpanded(listItemElement) {
|
|
11
|
+
return (listItemElement.getAttribute('aria-expanded') === 'true');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {Element} listItemElement
|
|
16
|
+
* @param {boolean} value
|
|
17
|
+
* @return {void}
|
|
18
|
+
*/
|
|
19
|
+
export function setExpanded(listItemElement, value) {
|
|
20
|
+
listItemElement.setAttribute('aria-expanded', value ? 'true' : 'false');
|
|
21
|
+
for (const treeitem of listItemElement.querySelectorAll('[role="treeitem"]')) {
|
|
22
|
+
treeitem.setAttribute('mdw-skip-tab', value ? 'false' : 'true');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Event} event
|
|
28
|
+
* @return {void}
|
|
29
|
+
*/
|
|
30
|
+
export function onChildContentActivate(event) {
|
|
31
|
+
const activatedElement = /** @type {HTMLElement} */ (event.target);
|
|
32
|
+
const element = /** @type {HTMLElement} */ (event.currentTarget);
|
|
33
|
+
if (!activatedElement || activatedElement.parentElement !== element) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (element.hasAttribute('aria-expanded')) {
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
setExpanded(element, !isExpanded(element));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {Element} listItemElement
|
|
44
|
+
* @return {void}
|
|
45
|
+
*/
|
|
46
|
+
export function setupAria(listItemElement) {
|
|
47
|
+
let isTreeItem = null;
|
|
48
|
+
let roleIsNone = false;
|
|
49
|
+
if (!listItemElement.hasAttribute('role')) {
|
|
50
|
+
if (listItemElement.hasAttribute('aria-expanded')) {
|
|
51
|
+
listItemElement.setAttribute('role', 'treeitem');
|
|
52
|
+
isTreeItem = true;
|
|
53
|
+
roleIsNone = false;
|
|
54
|
+
} else {
|
|
55
|
+
listItemElement.setAttribute('role', 'none');
|
|
56
|
+
isTreeItem = false;
|
|
57
|
+
roleIsNone = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (isTreeItem !== false || listItemElement.getAttribute('role') === 'treeitem') {
|
|
61
|
+
const activatorContent = getChildElementByClass(listItemElement, 'mdw-list__content');
|
|
62
|
+
if (activatorContent && !activatorContent.hasAttribute('role')) {
|
|
63
|
+
activatorContent.setAttribute('role', 'none');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!roleIsNone) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const parentRole = listItemElement.parentElement && listItemElement.parentElement.getAttribute('role');
|
|
70
|
+
if (!parentRole) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const contentChild = getChildElementByClass(listItemElement, 'mdw-list__content');
|
|
74
|
+
if (!contentChild) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (contentChild.hasAttribute('role')) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
switch (parentRole) {
|
|
81
|
+
case 'listbox':
|
|
82
|
+
contentChild.setAttribute('role', 'option');
|
|
83
|
+
break;
|
|
84
|
+
case 'radiogroup':
|
|
85
|
+
contentChild.setAttribute('role', 'radio');
|
|
86
|
+
break;
|
|
87
|
+
case 'group':
|
|
88
|
+
case 'tree':
|
|
89
|
+
case 'treeitem':
|
|
90
|
+
contentChild.setAttribute('role', 'treeitem');
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
case 'list':
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {KeyboardEvent} event
|
|
99
|
+
* @return {void}
|
|
100
|
+
*/
|
|
101
|
+
function onKeyDown(event) {
|
|
102
|
+
if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (event.key !== 'Enter' && event.key !== 'Spacebar' && event.key !== ' ') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (document.activeElement !== event.currentTarget) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const element = /** @type {HTMLElement} */ (event.currentTarget);
|
|
112
|
+
if (!element) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (!element.hasAttribute('aria-expanded')) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const activatorContent = getChildElementByClass(element, 'mdw-list__content');
|
|
119
|
+
if (!activatorContent) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
event.stopPropagation();
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
const newEvent = document.createEvent('Event');
|
|
125
|
+
newEvent.initEvent('click', true, true);
|
|
126
|
+
activatorContent.dispatchEvent(newEvent);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {Element} listItemElement
|
|
131
|
+
* @return {void}
|
|
132
|
+
*/
|
|
133
|
+
export function attachCore(listItemElement) {
|
|
134
|
+
setupAria(listItemElement);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @param {Element} listItemElement
|
|
138
|
+
* @return {void}
|
|
139
|
+
*/
|
|
140
|
+
export function attach(listItemElement) {
|
|
141
|
+
attachCore(listItemElement);
|
|
142
|
+
for (const element of listItemElement.getElementsByClassName('mdw-list__content')) { ListContent.attach(element); }
|
|
143
|
+
if (listItemElement.hasAttribute('aria-expanded')) {
|
|
144
|
+
if (!listItemElement.hasAttribute('mdw-expander-js')) {
|
|
145
|
+
listItemElement.setAttribute('mdw-pre-expander-js', '');
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
if (listItemElement.hasAttribute('mdw-pre-expander-js')) {
|
|
148
|
+
listItemElement.removeAttribute('mdw-pre-expander-js');
|
|
149
|
+
listItemElement.setAttribute('mdw-expander-js', '');
|
|
150
|
+
}
|
|
151
|
+
}, 500);
|
|
152
|
+
}
|
|
153
|
+
setExpanded(listItemElement, isExpanded(listItemElement));
|
|
154
|
+
}
|
|
155
|
+
listItemElement.addEventListener(ListContent.ACTIVATE_EVENT, onChildContentActivate);
|
|
156
|
+
listItemElement.addEventListener('keydown', onKeyDown);
|
|
157
|
+
Keyboard.attach(listItemElement);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {Element} listItemElement
|
|
162
|
+
* @return {void}
|
|
163
|
+
*/
|
|
164
|
+
export function detach(listItemElement) {
|
|
165
|
+
Keyboard.detach(listItemElement);
|
|
166
|
+
for (const element of listItemElement.getElementsByClassName('mdw-list__content')) { ListContent.detach(element); }
|
|
167
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { dispatchDomEvent } from '../../core/dom.js';
|
|
2
|
+
|
|
3
|
+
export const SECONDARY_ACTION_EVENT = 'mdw:listsecondary-action';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Event} event
|
|
7
|
+
* @return {void}
|
|
8
|
+
*/
|
|
9
|
+
export function onInteraction(event) {
|
|
10
|
+
event.stopPropagation();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {MouseEvent|KeyboardEvent|PointerEvent} event
|
|
15
|
+
* @return {void}
|
|
16
|
+
*/
|
|
17
|
+
export function onClick(event) {
|
|
18
|
+
event.stopPropagation();
|
|
19
|
+
const listSecondaryElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
20
|
+
dispatchDomEvent(listSecondaryElement, SECONDARY_ACTION_EVENT);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {Element} listSecondaryElement
|
|
25
|
+
* @return {void}
|
|
26
|
+
*/
|
|
27
|
+
export function attach(listSecondaryElement) {
|
|
28
|
+
if (!listSecondaryElement.hasAttribute('mdw-action')) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
listSecondaryElement.addEventListener('click', onClick);
|
|
32
|
+
listSecondaryElement.addEventListener('mousedown', onInteraction, { passive: true });
|
|
33
|
+
listSecondaryElement.addEventListener('touchstart', onInteraction, { passive: true });
|
|
34
|
+
listSecondaryElement.addEventListener('keydown', onInteraction, { passive: true });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @param {Element} listSecondaryElement
|
|
38
|
+
* @return {void}
|
|
39
|
+
*/
|
|
40
|
+
export function detach(listSecondaryElement) {
|
|
41
|
+
listSecondaryElement.removeEventListener('click', onClick);
|
|
42
|
+
listSecondaryElement.removeEventListener('mousedown', onInteraction);
|
|
43
|
+
listSecondaryElement.removeEventListener('touchstart', onInteraction);
|
|
44
|
+
listSecondaryElement.removeEventListener('keydown', onInteraction);
|
|
45
|
+
}
|