@shortfuse/materialdesignweb 0.0.9 → 0.4.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 +3 -0
- package/.eslintrc.json +146 -27
- package/.stylelintrc.json +598 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/.vscode/tasks.json +19 -10
- package/CHANGELOG.md +24 -0
- package/README.md +84 -2
- package/adapters/datatable/column.js +203 -0
- package/adapters/datatable/index.js +972 -0
- package/adapters/dom/index.js +601 -0
- package/adapters/list/index.js +69 -0
- package/adapters/search/index.js +521 -0
- package/components/appbar/_spec.scss +225 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +118 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +85 -0
- package/components/bottomnav/_spec.scss +157 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +122 -0
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +89 -0
- package/components/{core/button → button}/README.md +16 -22
- package/components/button/_spec.scss +161 -0
- package/components/button/_theme.scss +65 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +43 -0
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +249 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +134 -0
- package/components/chip/_theme.scss +177 -0
- package/components/chip/index.js +21 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +288 -0
- package/components/datatable/_theme.scss +154 -0
- package/components/datatable/cell.js +45 -0
- package/components/datatable/columnheader.js +47 -0
- package/components/datatable/index.js +388 -0
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +49 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +213 -0
- package/components/dialog/_theme.scss +0 -0
- package/components/dialog/index.js +627 -0
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +13 -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/_spec.scss +222 -0
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +103 -0
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +312 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +33 -0
- package/components/layout/_spec.scss +1012 -0
- package/components/layout/_theme.scss +44 -0
- package/components/layout/index.js +464 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +397 -0
- package/components/list/_theme.scss +111 -0
- package/components/list/content.js +110 -0
- package/components/list/index.js +260 -0
- package/components/list/index.scss +2 -0
- package/components/list/item.js +170 -0
- package/components/list/secondary.js +46 -0
- package/components/menu/_spec.scss +362 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +721 -0
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +239 -0
- package/components/{core/progress/style.scss → progress/_spec.scss} +36 -25
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +36 -0
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +386 -0
- package/components/selection/_theme.scss +166 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +76 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +56 -0
- package/components/selection/radiogroup.js +47 -0
- package/components/slider/_spec.scss +64 -0
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +195 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +344 -0
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +235 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +205 -0
- package/components/tab/index.js +260 -0
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +89 -0
- package/components/tab/list.js +210 -0
- package/components/tab/panel.js +54 -0
- package/components/template/_theme.scss +27 -0
- package/components/{core/textfield → textfield}/README.md +70 -50
- package/components/textfield/_mixins.scss +52 -0
- package/components/textfield/_spec.scss +809 -0
- package/components/textfield/_theme.scss +299 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +168 -0
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +188 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +224 -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 +38 -0
- package/core/_length.scss +9 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +34 -0
- package/core/_type.scss +127 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +50 -0
- package/core/aria/keyboard.js +93 -0
- package/core/aria/rovingtabindex.js +178 -0
- package/core/aria/tab.js +60 -0
- package/core/color/_spec.scss +0 -0
- package/core/color/_theme.scss +390 -0
- package/core/color/index.scss +2 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +271 -0
- package/core/overlay/_spec.scss +31 -0
- package/core/overlay/_theme.scss +171 -0
- package/core/overlay/index.js +108 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +197 -0
- package/core/ripple/_theme.scss +40 -0
- package/core/ripple/index.js +294 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_config.scss +2 -0
- package/core/theme/_mixins.scss +172 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -150
- package/core/theme/_variables.scss +24 -0
- package/core/theme/index.js +50 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +468 -0
- package/docs/_flex.scss +22 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_mixins.pug +155 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +29 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +149 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +93 -0
- package/docs/_storage.js +33 -0
- package/docs/docs.scss +295 -0
- package/docs/index.eta +16 -0
- package/docs/index.js +0 -0
- package/docs/pages/appbar.eta +114 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/appbar.pug +78 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +115 -0
- package/docs/pages/bottomnav.pug +137 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/button.pug +121 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +177 -0
- package/docs/pages/card.pug +74 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +82 -0
- package/docs/pages/chip.pug +91 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +262 -0
- package/docs/pages/color.pug +121 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +164 -0
- package/docs/pages/datatable.pug +283 -0
- package/docs/pages/dialog.eta +186 -0
- package/docs/pages/dialog.js +177 -0
- package/docs/pages/dialog.pug +132 -0
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +143 -0
- package/docs/pages/dom.pug +22 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/elevation.pug +25 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/pages/fab.js +44 -0
- package/docs/pages/fab.pug +66 -0
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/grid.pug +95 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/layout.pug +7 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +9 -0
- package/docs/pages/list.pug +326 -0
- package/docs/pages/menu.eta +276 -0
- package/docs/pages/menu.js +217 -0
- package/docs/pages/menu.pug +205 -0
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +4 -0
- package/docs/pages/overlay.pug +55 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/pages/progress.js +12 -0
- package/docs/pages/progress.pug +16 -0
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +4 -0
- package/docs/pages/ripple.pug +21 -0
- package/docs/pages/search.eta +246 -0
- package/docs/pages/search.js +243 -0
- package/docs/pages/search.pug +165 -0
- package/docs/pages/selection.eta +111 -0
- package/docs/pages/selection.js +13 -0
- package/docs/pages/selection.pug +74 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/slider.pug +17 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/pages/snackbar.js +158 -0
- package/docs/pages/snackbar.pug +60 -0
- package/docs/pages/tab.eta +421 -0
- package/docs/pages/tab.js +151 -0
- package/docs/pages/tab.pug +304 -0
- package/docs/pages/textfield.eta +486 -0
- package/docs/pages/textfield.js +254 -0
- package/docs/pages/textfield.pug +360 -0
- package/docs/pages/tooltip.eta +94 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/tooltip.pug +78 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +54 -0
- package/docs/pages/transition.pug +76 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/pages/type.pug +29 -0
- package/docs/postrender.js +39 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_dialogs.pug +96 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/_menus.pug +11 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +480 -0
- package/docs/pwa/pwa.js +306 -0
- package/docs/pwa/pwa.pug +325 -0
- package/docs/pwa/pwa.scss +26 -0
- package/docs/spec.scss +26 -0
- package/docs/themes/_component-themes.scss +26 -0
- package/docs/themes/theme-colored-fallbacks.scss +17 -0
- package/docs/themes/theme-colored.scss +17 -0
- package/docs/themes/theme-default-fallbacks.scss +17 -0
- package/docs/themes/theme-default.scss +17 -0
- package/jsconfig.json +4 -2
- package/package.json +43 -28
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/utils/function.js +3 -0
- package/webpack.config.cjs +257 -0
- package/components/_index.scss +0 -4
- package/components/all-components.scss +0 -14
- package/components/common/functions.scss +0 -173
- package/components/common/mixins.scss +0 -107
- package/components/common/motion.scss +0 -36
- package/components/common/ripple.scss +0 -92
- package/components/common/variables.scss +0 -48
- package/components/complex/dialog/style.scss +0 -159
- package/components/complex/dialog/theming.scss +0 -29
- package/components/complex/navdrawer/style.scss +0 -477
- package/components/complex/navdrawer/theming.scss +0 -58
- package/components/complex/search/index.js +0 -492
- package/components/core/bottomnav/README.md +0 -85
- package/components/core/bottomnav/index.js +0 -140
- package/components/core/bottomnav/style.scss +0 -173
- package/components/core/bottomnav/theming.scss +0 -42
- package/components/core/button/index.js +0 -52
- package/components/core/button/style.scss +0 -283
- package/components/core/button/theming.scss +0 -131
- package/components/core/list/index.js +0 -94
- package/components/core/list/style.scss +0 -269
- package/components/core/list/theming.scss +0 -74
- package/components/core/menu/index.js +0 -127
- package/components/core/menu/style.scss +0 -239
- package/components/core/menu/theming.scss +0 -55
- package/components/core/progress/index.js +0 -33
- package/components/core/selection/style.scss +0 -249
- package/components/core/selection/theming.scss +0 -49
- package/components/core/switch/style.scss +0 -3
- package/components/core/tab/index.js +0 -174
- package/components/core/tab/style.scss +0 -202
- package/components/core/tab/theming.scss +0 -43
- package/components/core/textfield/index.js +0 -169
- package/components/core/textfield/style.scss +0 -672
- package/components/core/textfield/theming.scss +0 -262
- package/components/core/toolbar/style.scss +0 -109
- package/components/core/toolbar/theming.scss +0 -28
- package/components/core/tooltip/style.scss +0 -127
- package/components/core/type/style.scss +0 -133
- package/components/core/type/theming.scss +0 -25
- package/components/index.js +0 -24
- package/components/template/theming.scss +0 -31
- package/components/theming/theming.scss +0 -504
- package/docs/bottomnav.html +0 -171
- package/docs/bottomnav.min.js +0 -383
- package/docs/button.html +0 -322
- package/docs/button.min.js +0 -251
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -83
- package/docs/dialog.html +0 -103
- package/docs/dialog.min.js +0 -160
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -83
- package/docs/index.html +0 -55
- package/docs/index.min.js +0 -83
- package/docs/list.html +0 -442
- package/docs/list.min.js +0 -312
- package/docs/menu.html +0 -185
- package/docs/menu.min.js +0 -370
- package/docs/navdrawer.html +0 -199
- package/docs/navdrawer.min.js +0 -244
- package/docs/progress.html +0 -75
- package/docs/progress.min.js +0 -162
- package/docs/search.html +0 -230
- package/docs/search.min.js +0 -1202
- package/docs/selection.html +0 -188
- package/docs/selection.min.js +0 -160
- package/docs/src/complex/dialog.js +0 -3
- package/docs/src/complex/dialog.pug +0 -44
- package/docs/src/complex/navdrawer.js +0 -82
- package/docs/src/complex/navdrawer.pug +0 -109
- package/docs/src/complex/search.js +0 -207
- package/docs/src/complex/search.pug +0 -143
- package/docs/src/components.scss +0 -1
- package/docs/src/core/bottomnav.js +0 -22
- package/docs/src/core/bottomnav.pug +0 -93
- package/docs/src/core/button.js +0 -16
- package/docs/src/core/button.pug +0 -73
- package/docs/src/core/list.js +0 -21
- package/docs/src/core/list.pug +0 -246
- package/docs/src/core/menu.js +0 -33
- package/docs/src/core/menu.pug +0 -108
- package/docs/src/core/progress.js +0 -11
- package/docs/src/core/progress.pug +0 -17
- package/docs/src/core/selection.js +0 -4
- package/docs/src/core/selection.pug +0 -92
- package/docs/src/core/tab.js +0 -21
- package/docs/src/core/tab.pug +0 -180
- package/docs/src/core/textfield.js +0 -15
- package/docs/src/core/textfield.pug +0 -274
- package/docs/src/core/toolbar.js +0 -4
- package/docs/src/core/toolbar.pug +0 -79
- package/docs/src/core/tooltip.js +0 -4
- package/docs/src/core/tooltip.pug +0 -76
- package/docs/src/core/type.js +0 -4
- package/docs/src/core/type.pug +0 -36
- package/docs/src/docs.scss +0 -200
- package/docs/src/index.pug +0 -5
- package/docs/src/mixins.pug +0 -72
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -35
- package/docs/src/theming.scss +0 -36
- package/docs/tab.html +0 -301
- package/docs/tab.min.js +0 -397
- package/docs/textfield.html +0 -476
- package/docs/textfield.min.js +0 -381
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -83
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -83
- package/docs/toolbar.html +0 -213
- package/docs/toolbar.min.js +0 -160
- package/docs/tooltip.html +0 -138
- package/docs/tooltip.min.js +0 -160
- package/docs/type.html +0 -94
- package/docs/type.min.js +0 -160
- package/webpack.config.js +0 -176
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Touch support based mixins
|
|
2
|
+
@mixin ifHasTouch {
|
|
3
|
+
@media (any-pointer: coarse) {
|
|
4
|
+
@content;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@mixin ifNoTouch {
|
|
9
|
+
@media not all and (any-pointer: coarse) {
|
|
10
|
+
@content;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Browser specific mixins
|
|
15
|
+
@mixin ifIE {
|
|
16
|
+
@media all\0 {
|
|
17
|
+
@content;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@mixin ifEdge {
|
|
22
|
+
@supports (-ms-ime-align:auto) {
|
|
23
|
+
@content;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@mixin ifMS {
|
|
28
|
+
@include ifIE {
|
|
29
|
+
@content;
|
|
30
|
+
}
|
|
31
|
+
@include ifEdge {
|
|
32
|
+
@content;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/core/_type.scss
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
@use './_length.scss' as *;
|
|
2
|
+
|
|
3
|
+
$weightThin: 100 !default;
|
|
4
|
+
$weightLight: 300 !default;
|
|
5
|
+
$weightRegular: 400 !default;
|
|
6
|
+
$weightMedium: 500 !default;
|
|
7
|
+
$weightBold: 700 !default;
|
|
8
|
+
$weightBlack: 900 !default;
|
|
9
|
+
|
|
10
|
+
$types: (
|
|
11
|
+
h1: (
|
|
12
|
+
font-weight: $weightLight,
|
|
13
|
+
letter-spacing: sp(-1.5),
|
|
14
|
+
font-size: sp(96),
|
|
15
|
+
line-height: sp(112),
|
|
16
|
+
),
|
|
17
|
+
h2: (
|
|
18
|
+
font-weight: $weightLight,
|
|
19
|
+
letter-spacing: sp(-0.5),
|
|
20
|
+
font-size: sp(60),
|
|
21
|
+
line-height: sp(72),
|
|
22
|
+
),
|
|
23
|
+
h3: (
|
|
24
|
+
font-weight: $weightRegular,
|
|
25
|
+
letter-spacing: 0,
|
|
26
|
+
font-size: sp(48),
|
|
27
|
+
line-height: sp(56),
|
|
28
|
+
),
|
|
29
|
+
h4: (
|
|
30
|
+
font-weight: $weightRegular,
|
|
31
|
+
letter-spacing: sp(0.25),
|
|
32
|
+
font-size: sp(34),
|
|
33
|
+
line-height: sp(40),
|
|
34
|
+
),
|
|
35
|
+
h5: (
|
|
36
|
+
font-weight: $weightRegular,
|
|
37
|
+
letter-spacing: 0,
|
|
38
|
+
font-size: sp(24),
|
|
39
|
+
line-height: sp(28),
|
|
40
|
+
),
|
|
41
|
+
h6: (
|
|
42
|
+
font-weight: $weightMedium,
|
|
43
|
+
letter-spacing: sp(0.15),
|
|
44
|
+
font-size: sp(20),
|
|
45
|
+
line-height: sp(24),
|
|
46
|
+
),
|
|
47
|
+
subtitle: (
|
|
48
|
+
font-weight: $weightRegular,
|
|
49
|
+
letter-spacing: sp(0.15),
|
|
50
|
+
font-size: sp(16),
|
|
51
|
+
line-height: sp(20),
|
|
52
|
+
),
|
|
53
|
+
subtitle-2: (
|
|
54
|
+
font-weight: $weightMedium,
|
|
55
|
+
letter-spacing: sp(0.1),
|
|
56
|
+
font-size: sp(14),
|
|
57
|
+
line-height: sp(16),
|
|
58
|
+
),
|
|
59
|
+
body: (
|
|
60
|
+
font-weight: $weightRegular,
|
|
61
|
+
letter-spacing: sp(0.5),
|
|
62
|
+
font-size: sp(16),
|
|
63
|
+
line-height: sp(24),
|
|
64
|
+
),
|
|
65
|
+
body-2: (
|
|
66
|
+
font-weight: $weightRegular,
|
|
67
|
+
letter-spacing: sp(0.25),
|
|
68
|
+
font-size: sp(14),
|
|
69
|
+
line-height: sp(20),
|
|
70
|
+
),
|
|
71
|
+
button: (
|
|
72
|
+
font-weight: $weightMedium,
|
|
73
|
+
text-transform: uppercase,
|
|
74
|
+
letter-spacing: sp(1.25),
|
|
75
|
+
font-size: sp(14),
|
|
76
|
+
line-height: sp(16),
|
|
77
|
+
),
|
|
78
|
+
caption: (
|
|
79
|
+
font-weight: $weightRegular,
|
|
80
|
+
letter-spacing: sp(0.4),
|
|
81
|
+
font-size: sp(12),
|
|
82
|
+
line-height: sp(16),
|
|
83
|
+
),
|
|
84
|
+
overline: (
|
|
85
|
+
font-weight: $weightRegular,
|
|
86
|
+
letter-spacing: sp(1.5),
|
|
87
|
+
font-size: sp(10),
|
|
88
|
+
line-height: sp(12),
|
|
89
|
+
),
|
|
90
|
+
) !default;
|
|
91
|
+
|
|
92
|
+
@mixin addRules($type) {
|
|
93
|
+
$rules: map-get($types, $type);
|
|
94
|
+
@each $key in map-keys($rules) {
|
|
95
|
+
#{$key}: map-get($rules, $key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@mixin baselineToTop($dp) {
|
|
100
|
+
&::before {
|
|
101
|
+
content: '';
|
|
102
|
+
|
|
103
|
+
display: inline-block;
|
|
104
|
+
|
|
105
|
+
height: dp($dp);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@mixin baselineToBottom($dp) {
|
|
110
|
+
&::after {
|
|
111
|
+
content: '';
|
|
112
|
+
|
|
113
|
+
display: inline-block;
|
|
114
|
+
vertical-align: dp(-$dp);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@mixin textTopToTop($dp) {
|
|
119
|
+
&::before {
|
|
120
|
+
content: "\200B";
|
|
121
|
+
|
|
122
|
+
display: inline-block;
|
|
123
|
+
|
|
124
|
+
height: 1em;
|
|
125
|
+
margin-top: dp($dp);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { dispatchDomEvent } from '../dom.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} name Attribute Name
|
|
5
|
+
* @param {Element} element Element
|
|
6
|
+
* @param {string|boolean} value Boolean Attribute Value
|
|
7
|
+
* @param {string} [dispatchEventName] OnChangeEvent
|
|
8
|
+
* @param {boolean} [explicit=true]
|
|
9
|
+
* @param {string} [emptyValue=false] Default empty value
|
|
10
|
+
* @return {boolean} successful
|
|
11
|
+
*/
|
|
12
|
+
function setAttribute(name, element, value, dispatchEventName, explicit = true, emptyValue = 'false') {
|
|
13
|
+
const attr = element.getAttribute(name);
|
|
14
|
+
let stringValue;
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
stringValue = value;
|
|
17
|
+
} else {
|
|
18
|
+
stringValue = (value ? 'true' : 'false');
|
|
19
|
+
}
|
|
20
|
+
if (attr === stringValue) {
|
|
21
|
+
// Nothing to change
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (stringValue === emptyValue) {
|
|
25
|
+
// Set default empty value
|
|
26
|
+
if (attr == null) {
|
|
27
|
+
// No attribute set
|
|
28
|
+
if (explicit) {
|
|
29
|
+
// Explicitly set attribute
|
|
30
|
+
element.setAttribute(name, stringValue);
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (!explicit) {
|
|
35
|
+
element.removeAttribute(name);
|
|
36
|
+
} else {
|
|
37
|
+
element.setAttribute(name, stringValue);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
// Non default value;
|
|
41
|
+
element.setAttribute(name, stringValue);
|
|
42
|
+
}
|
|
43
|
+
if (!dispatchEventName) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// Alert change
|
|
47
|
+
if (!dispatchDomEvent(element, dispatchEventName, { value: stringValue })) {
|
|
48
|
+
// Revert
|
|
49
|
+
if (attr == null) {
|
|
50
|
+
element.removeAttribute(name);
|
|
51
|
+
} else {
|
|
52
|
+
element.setAttribute(name, attr);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {Element} element
|
|
61
|
+
* @param {string|boolean} value
|
|
62
|
+
* @param {string} [dispatchEventName]
|
|
63
|
+
* @return {boolean} successful
|
|
64
|
+
*/
|
|
65
|
+
export function setCurrent(element, value, dispatchEventName) {
|
|
66
|
+
// Some browsers incorrectly style [aria-current="false"]
|
|
67
|
+
// Attribute will be removed when false|"false"
|
|
68
|
+
return setAttribute('aria-current', element, value, dispatchEventName, false);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {Element} element
|
|
73
|
+
* @param {string|boolean} value
|
|
74
|
+
* @param {string} [dispatchEventName]
|
|
75
|
+
* @return {boolean} successful
|
|
76
|
+
*/
|
|
77
|
+
export function setSelected(element, value, dispatchEventName) {
|
|
78
|
+
return setAttribute('aria-selected', element, value, dispatchEventName);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {Element} element
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
export function isChecked(element) {
|
|
86
|
+
return element.getAttribute('aria-checked') === 'true';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {Element} element
|
|
91
|
+
* @param {string|boolean} value
|
|
92
|
+
* @param {string} [dispatchEventName]
|
|
93
|
+
* @return {boolean} successful
|
|
94
|
+
*/
|
|
95
|
+
export function setChecked(element, value, dispatchEventName) {
|
|
96
|
+
return setAttribute('aria-checked', element, value, dispatchEventName);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {Element} element
|
|
101
|
+
* @return {boolean}
|
|
102
|
+
*/
|
|
103
|
+
export function isDisabled(element) {
|
|
104
|
+
return element.getAttribute('aria-disabled') === 'true';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Element} element
|
|
109
|
+
* @param {string|boolean} value
|
|
110
|
+
* @param {string} [dispatchEventName]
|
|
111
|
+
* @return {boolean} successful
|
|
112
|
+
*/
|
|
113
|
+
export function setDisabled(element, value, dispatchEventName) {
|
|
114
|
+
return setAttribute('aria-disabled', element, value, dispatchEventName);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {Element} element
|
|
119
|
+
* @return {boolean}
|
|
120
|
+
*/
|
|
121
|
+
export function isExpanded(element) {
|
|
122
|
+
return element.getAttribute('aria-expanded') === 'true';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {Element} element
|
|
127
|
+
* @param {string|boolean} value
|
|
128
|
+
* @param {string} [dispatchEventName]
|
|
129
|
+
* @return {boolean} successful
|
|
130
|
+
*/
|
|
131
|
+
export function setExpanded(element, value, dispatchEventName) {
|
|
132
|
+
return setAttribute('aria-expanded', element, value, dispatchEventName);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {Element} element
|
|
137
|
+
* @return {boolean}
|
|
138
|
+
*/
|
|
139
|
+
export function isReadonly(element) {
|
|
140
|
+
return element.getAttribute('aria-readonly') === 'true';
|
|
141
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#button
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {KeyboardEvent} event
|
|
5
|
+
* @return {void}
|
|
6
|
+
*/
|
|
7
|
+
function onKeyDown(event) {
|
|
8
|
+
if (event.key !== 'Enter' && event.key !== 'Spacebar' && event.key !== ' ') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
/** @type {HTMLElement} */
|
|
12
|
+
const buttonElement = (event.currentTarget);
|
|
13
|
+
if (!buttonElement) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (buttonElement.getAttribute('aria-disabled') === 'true') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
event.stopPropagation();
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
const newEvent = document.createEvent('Event');
|
|
22
|
+
newEvent.initEvent('click', true, true);
|
|
23
|
+
buttonElement.dispatchEvent(newEvent);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Element} element
|
|
28
|
+
* @return {void}
|
|
29
|
+
*/
|
|
30
|
+
export function attach(element) {
|
|
31
|
+
element.setAttribute('role', 'button');
|
|
32
|
+
if (element instanceof HTMLButtonElement === false
|
|
33
|
+
&& !element.hasAttribute('tabindex')) {
|
|
34
|
+
element.setAttribute('tabindex', '0');
|
|
35
|
+
}
|
|
36
|
+
element.setAttribute('mdw-aria-button-js', '');
|
|
37
|
+
if (element instanceof HTMLButtonElement === false
|
|
38
|
+
&& element instanceof HTMLInputElement === false) {
|
|
39
|
+
element.addEventListener('keydown', onKeyDown);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {Element} element
|
|
45
|
+
* @return {void}
|
|
46
|
+
*/
|
|
47
|
+
export function detach(element) {
|
|
48
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
49
|
+
element.removeAttribute('mdw-aria-button-js');
|
|
50
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Keyboard Navigation
|
|
2
|
+
|
|
3
|
+
import { dispatchDomEvent, isRtl } from '../dom.js';
|
|
4
|
+
|
|
5
|
+
export const FORWARD_ARROW_KEY = 'mdw:keyboard-forwardarrowkey';
|
|
6
|
+
export const BACK_ARROW_KEY = 'mdw:keyboard-backarrowkey';
|
|
7
|
+
export const UP_ARROW_KEY = 'mdw:keyboard-uparrowkey';
|
|
8
|
+
export const DOWN_ARROW_KEY = 'mdw:keyboard-downarrowkey';
|
|
9
|
+
export const HOME_KEY = 'mdw:keyboard-homekey';
|
|
10
|
+
export const END_KEY = 'mdw:keyboard-endkey';
|
|
11
|
+
export const PAGEUP_KEY = 'mdw:keyboard-pageupkey';
|
|
12
|
+
export const PAGEDOWN_KEY = 'mdw:keyboard-pagedownkey';
|
|
13
|
+
export const SPACEBAR_KEY = 'mdw:keyboard-spacebarkey';
|
|
14
|
+
export const ENTER_KEY = 'mdw:keyboard-enterkey';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {KeyboardEvent} event
|
|
18
|
+
* @return {void}
|
|
19
|
+
*/
|
|
20
|
+
function onKeyDownHandler(event) {
|
|
21
|
+
/** @type {Element} */
|
|
22
|
+
const element = (event.currentTarget);
|
|
23
|
+
const detail = {
|
|
24
|
+
ctrlKey: event.ctrlKey,
|
|
25
|
+
shiftKey: event.shiftKey,
|
|
26
|
+
altKey: event.altKey,
|
|
27
|
+
metaKey: event.metaKey,
|
|
28
|
+
repeat: event.repeat,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let type;
|
|
32
|
+
switch (event.key) {
|
|
33
|
+
case 'Enter':
|
|
34
|
+
type = ENTER_KEY;
|
|
35
|
+
break;
|
|
36
|
+
case ' ':
|
|
37
|
+
case 'Spacebar':
|
|
38
|
+
type = SPACEBAR_KEY;
|
|
39
|
+
break;
|
|
40
|
+
case 'ArrowDown':
|
|
41
|
+
case 'Down':
|
|
42
|
+
type = DOWN_ARROW_KEY;
|
|
43
|
+
break;
|
|
44
|
+
case 'ArrowUp':
|
|
45
|
+
case 'Up':
|
|
46
|
+
type = UP_ARROW_KEY;
|
|
47
|
+
break;
|
|
48
|
+
case 'ArrowLeft':
|
|
49
|
+
case 'Left':
|
|
50
|
+
type = isRtl() ? FORWARD_ARROW_KEY : BACK_ARROW_KEY;
|
|
51
|
+
break;
|
|
52
|
+
case 'ArrowRight':
|
|
53
|
+
case 'Right':
|
|
54
|
+
type = isRtl() ? BACK_ARROW_KEY : FORWARD_ARROW_KEY;
|
|
55
|
+
break;
|
|
56
|
+
case 'Home':
|
|
57
|
+
type = HOME_KEY;
|
|
58
|
+
break;
|
|
59
|
+
case 'End':
|
|
60
|
+
type = END_KEY;
|
|
61
|
+
break;
|
|
62
|
+
case 'PageUp':
|
|
63
|
+
type = PAGEUP_KEY;
|
|
64
|
+
break;
|
|
65
|
+
case 'PageDown':
|
|
66
|
+
type = PAGEDOWN_KEY;
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!dispatchDomEvent(element, type, detail)) {
|
|
73
|
+
// preventDefault called
|
|
74
|
+
event.stopPropagation();
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {Element} element
|
|
81
|
+
* @return {void}
|
|
82
|
+
*/
|
|
83
|
+
export function attach(element) {
|
|
84
|
+
element.addEventListener('keydown', onKeyDownHandler);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {Element} element
|
|
89
|
+
* @return {void}
|
|
90
|
+
*/
|
|
91
|
+
export function detach(element) {
|
|
92
|
+
element.removeEventListener('keydown', onKeyDownHandler);
|
|
93
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#kbd_roving_tabindex
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
dispatchDomEvent,
|
|
5
|
+
iterateArrayLike,
|
|
6
|
+
iterateSomeOfArrayLike,
|
|
7
|
+
} from '../dom.js';
|
|
8
|
+
|
|
9
|
+
export const TABINDEX_ZEROED = 'mdw:rovingtabindex-tabindexzeroed';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {FocusEvent} event
|
|
13
|
+
* @return {void}
|
|
14
|
+
*/
|
|
15
|
+
function onChildFocus(event) {
|
|
16
|
+
/** @type {Element} */
|
|
17
|
+
const child = (event.currentTarget);
|
|
18
|
+
if (child.getAttribute('tabindex') === '0') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
child.setAttribute('tabindex', '0');
|
|
22
|
+
dispatchDomEvent(child, TABINDEX_ZEROED);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {ArrayLike<Element>} items
|
|
27
|
+
* @param {Element[]} [excludeItems]
|
|
28
|
+
* @return {void}
|
|
29
|
+
*/
|
|
30
|
+
export function removeTabIndex(items, excludeItems = []) {
|
|
31
|
+
iterateArrayLike(items, (item) => {
|
|
32
|
+
if (excludeItems.indexOf(item) !== -1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (item.hasAttribute('tabindex')) {
|
|
36
|
+
item.setAttribute('tabindex', '-1');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {HTMLElement} element
|
|
43
|
+
* @return {boolean}
|
|
44
|
+
*/
|
|
45
|
+
function attemptFocus(element) {
|
|
46
|
+
try {
|
|
47
|
+
element.focus();
|
|
48
|
+
} catch (e) {
|
|
49
|
+
// Ignore error.
|
|
50
|
+
}
|
|
51
|
+
return document.activeElement === element;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {ArrayLike<HTMLElement>} list
|
|
56
|
+
* @param {Element} [current]
|
|
57
|
+
* @param {boolean} [loop=true]
|
|
58
|
+
* @param {boolean} [reverse]
|
|
59
|
+
* @return {void}
|
|
60
|
+
*/
|
|
61
|
+
export function selectNext(list, current = null, loop = true, reverse = false) {
|
|
62
|
+
let foundCurrent = false;
|
|
63
|
+
|
|
64
|
+
const iterateResult = iterateSomeOfArrayLike(list, (item, index, array) => {
|
|
65
|
+
const candidate = reverse ? (array[array.length - 1 - index]) : item;
|
|
66
|
+
if (!foundCurrent) {
|
|
67
|
+
if (current) {
|
|
68
|
+
if (candidate === current) {
|
|
69
|
+
foundCurrent = true;
|
|
70
|
+
}
|
|
71
|
+
} else if (candidate.getAttribute('tabindex') === '0') {
|
|
72
|
+
foundCurrent = true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (!candidate.hasAttribute('tabindex')) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (candidate.getAttribute('aria-hidden') === 'true') {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (candidate.getAttribute('mdw-skip-tab') === 'true') {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return attemptFocus(candidate);
|
|
86
|
+
});
|
|
87
|
+
if (iterateResult) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!loop) {
|
|
91
|
+
if (document.activeElement !== current && current instanceof HTMLElement) {
|
|
92
|
+
current.focus();
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
iterateSomeOfArrayLike(list, (item, index, array) => {
|
|
97
|
+
const candidate = reverse ? (array[array.length - 1 - index]) : item;
|
|
98
|
+
if (!candidate.hasAttribute('tabindex')) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (candidate.getAttribute('aria-hidden') === 'true') {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (candidate.getAttribute('mdw-skip-tab') === 'true') {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Abort if we've looped all the way back to original element
|
|
108
|
+
// Abort if candidate received focus
|
|
109
|
+
return (attemptFocus(candidate) || candidate === current);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Alias for selectNext(list, current, true);
|
|
115
|
+
* @param {ArrayLike<HTMLElement>} list
|
|
116
|
+
* @param {Element} [current]
|
|
117
|
+
* @param {boolean} [loop=true]
|
|
118
|
+
* @return {void}
|
|
119
|
+
*/
|
|
120
|
+
export function selectPrevious(list, current, loop = true) {
|
|
121
|
+
return selectNext(list, current, loop, true);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {Element} element
|
|
126
|
+
* @return {void}
|
|
127
|
+
*/
|
|
128
|
+
export function attach(element) {
|
|
129
|
+
if (!element.hasAttribute('tabindex')) {
|
|
130
|
+
element.setAttribute('tabindex', (document.activeElement === element) ? '0' : '-1');
|
|
131
|
+
}
|
|
132
|
+
element.addEventListener('focus', onChildFocus);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {Element} element
|
|
137
|
+
* @return {void}
|
|
138
|
+
*/
|
|
139
|
+
export function detach(element) {
|
|
140
|
+
element.removeEventListener('focus', onChildFocus);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {ArrayLike<Element>} items
|
|
145
|
+
* @param {boolean} [focusableWhenDisabled=true]
|
|
146
|
+
* @return {void}
|
|
147
|
+
*/
|
|
148
|
+
export function setupTabIndexes(items, focusableWhenDisabled = true) {
|
|
149
|
+
/** @type {Element} */
|
|
150
|
+
let currentlyFocusedChild = null;
|
|
151
|
+
/** @type {Element} */
|
|
152
|
+
let currentTabIndexChild = null;
|
|
153
|
+
/** @type {Element} */
|
|
154
|
+
let firstFocusableChild = null;
|
|
155
|
+
iterateArrayLike(items, (child) => {
|
|
156
|
+
if (!currentlyFocusedChild && document.activeElement === child) {
|
|
157
|
+
currentlyFocusedChild = child;
|
|
158
|
+
} else if (!currentTabIndexChild && child.getAttribute('tabindex') === '0') {
|
|
159
|
+
currentTabIndexChild = child;
|
|
160
|
+
} else {
|
|
161
|
+
if (!firstFocusableChild && child.getAttribute('aria-hidden') !== 'true'
|
|
162
|
+
&& (focusableWhenDisabled || child.getAttribute('aria-disabled') !== 'true')) {
|
|
163
|
+
firstFocusableChild = child;
|
|
164
|
+
}
|
|
165
|
+
child.setAttribute('tabindex', '-1');
|
|
166
|
+
}
|
|
167
|
+
attach(child);
|
|
168
|
+
});
|
|
169
|
+
if (currentlyFocusedChild) {
|
|
170
|
+
currentlyFocusedChild.setAttribute('tabindex', '0');
|
|
171
|
+
} else if (currentTabIndexChild) {
|
|
172
|
+
if (currentlyFocusedChild) {
|
|
173
|
+
currentTabIndexChild.setAttribute('tabindex', '-1');
|
|
174
|
+
}
|
|
175
|
+
} else if (firstFocusableChild) {
|
|
176
|
+
firstFocusableChild.setAttribute('tabindex', '0');
|
|
177
|
+
}
|
|
178
|
+
}
|
package/core/aria/tab.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-1.1/#tab
|
|
2
|
+
|
|
3
|
+
import * as Attributes from './attributes.js';
|
|
4
|
+
import * as Keyboard from './keyboard.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Element} element
|
|
8
|
+
* @param {string|boolean} value
|
|
9
|
+
* @param {string} [dispatchEventName]
|
|
10
|
+
* @return {boolean} successful
|
|
11
|
+
*/
|
|
12
|
+
export function setSelected(element, value, dispatchEventName) {
|
|
13
|
+
if (Attributes.setSelected(element, value, dispatchEventName)) {
|
|
14
|
+
Attributes.setCurrent(element, value);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Remap Space and Enter as Click
|
|
22
|
+
* @param {KeyboardEvent} event
|
|
23
|
+
* @return {void}
|
|
24
|
+
*/
|
|
25
|
+
function onKeyDown(event) {
|
|
26
|
+
if (event.key !== 'Enter' && event.key !== 'Spacebar' && event.key !== ' ') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
/** @type {HTMLElement} */
|
|
30
|
+
const element = (event.currentTarget);
|
|
31
|
+
if (!element) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
event.stopPropagation();
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
const newEvent = document.createEvent('Event');
|
|
37
|
+
newEvent.initEvent('click', true, true);
|
|
38
|
+
element.dispatchEvent(newEvent);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Element} element
|
|
43
|
+
* @return {void}
|
|
44
|
+
*/
|
|
45
|
+
export function attach(element) {
|
|
46
|
+
element.setAttribute('role', 'tab');
|
|
47
|
+
element.setAttribute('mdw-aria-tab-js', '');
|
|
48
|
+
element.addEventListener('keydown', onKeyDown);
|
|
49
|
+
Keyboard.attach(element);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {Element} element
|
|
54
|
+
* @return {void}
|
|
55
|
+
*/
|
|
56
|
+
export function detach(element) {
|
|
57
|
+
Keyboard.detach(element);
|
|
58
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
59
|
+
element.removeAttribute('mdw-aria-tab-js');
|
|
60
|
+
}
|
|
File without changes
|