@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Motion Durations
|
|
2
|
+
// https://material.io/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
|
|
3
|
+
|
|
4
|
+
$simpleDuration: 100ms !default;
|
|
5
|
+
$fadeInDuration: 150ms !default;
|
|
6
|
+
$fadeOutDuration: 75ms !default;
|
|
7
|
+
|
|
8
|
+
$shapeChangeDuration: 200ms !default;
|
|
9
|
+
$iconDuration: 500ms !default;
|
|
10
|
+
|
|
11
|
+
$expandDuration: 250ms !default;
|
|
12
|
+
$collapseDuration: 200ms !default;
|
|
13
|
+
|
|
14
|
+
$expandDurationFull: 300ms !default;
|
|
15
|
+
$collapseDurationFull: 250ms !default;
|
|
16
|
+
|
|
17
|
+
// Motion Easing Curves
|
|
18
|
+
// https://material.io/guidelines/motion/duration-easing.html#duration-easing-natural-easing-curves
|
|
19
|
+
|
|
20
|
+
// FastOutSlowInInterpolator
|
|
21
|
+
$standardEasing: cubic-bezier(0.4, 0.0, 0.2, 1) !default;
|
|
22
|
+
$standardPeakVelocity: 0.30 !default;
|
|
23
|
+
|
|
24
|
+
// LinearOutSlowInInterpolator
|
|
25
|
+
$decelerateEasing: cubic-bezier(0.0, 0.0, 0.2, 1) !default;
|
|
26
|
+
|
|
27
|
+
// FastOutLinearInInterpolator
|
|
28
|
+
$accelerateEasing: cubic-bezier(0.4, 0.0, 1, 1) !default;
|
|
29
|
+
|
|
30
|
+
// FastOutLinearInInterpolator
|
|
31
|
+
$sharpEasing: cubic-bezier(0.4, 0.0, 0.6, 1) !default;
|
package/core/_type.scss
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
@use 'sass:map';
|
|
2
|
+
@use './_length.scss' as *;
|
|
3
|
+
|
|
4
|
+
$weightThin: 100 !default;
|
|
5
|
+
$weightLight: 300 !default;
|
|
6
|
+
$weightRegular: 400 !default;
|
|
7
|
+
$weightMedium: 500 !default;
|
|
8
|
+
$weightBold: 700 !default;
|
|
9
|
+
$weightBlack: 900 !default;
|
|
10
|
+
|
|
11
|
+
$types: (
|
|
12
|
+
h1: (
|
|
13
|
+
font-weight: $weightLight,
|
|
14
|
+
letter-spacing: sp(-1.5),
|
|
15
|
+
font-size: sp(96),
|
|
16
|
+
line-height: sp(112),
|
|
17
|
+
),
|
|
18
|
+
h2: (
|
|
19
|
+
font-weight: $weightLight,
|
|
20
|
+
letter-spacing: sp(-0.5),
|
|
21
|
+
font-size: sp(60),
|
|
22
|
+
line-height: sp(72),
|
|
23
|
+
),
|
|
24
|
+
h3: (
|
|
25
|
+
font-weight: $weightRegular,
|
|
26
|
+
letter-spacing: 0,
|
|
27
|
+
font-size: sp(48),
|
|
28
|
+
line-height: sp(56),
|
|
29
|
+
),
|
|
30
|
+
h4: (
|
|
31
|
+
font-weight: $weightRegular,
|
|
32
|
+
letter-spacing: sp(0.25),
|
|
33
|
+
font-size: sp(34),
|
|
34
|
+
line-height: sp(40),
|
|
35
|
+
),
|
|
36
|
+
h5: (
|
|
37
|
+
font-weight: $weightRegular,
|
|
38
|
+
letter-spacing: 0,
|
|
39
|
+
font-size: sp(24),
|
|
40
|
+
line-height: sp(28),
|
|
41
|
+
),
|
|
42
|
+
h6: (
|
|
43
|
+
font-weight: $weightMedium,
|
|
44
|
+
letter-spacing: sp(0.15),
|
|
45
|
+
font-size: sp(20),
|
|
46
|
+
line-height: sp(24),
|
|
47
|
+
),
|
|
48
|
+
subtitle: (
|
|
49
|
+
font-weight: $weightRegular,
|
|
50
|
+
letter-spacing: sp(0.15),
|
|
51
|
+
font-size: sp(16),
|
|
52
|
+
line-height: sp(20),
|
|
53
|
+
),
|
|
54
|
+
subtitle-2: (
|
|
55
|
+
font-weight: $weightMedium,
|
|
56
|
+
letter-spacing: sp(0.1),
|
|
57
|
+
font-size: sp(14),
|
|
58
|
+
line-height: sp(16),
|
|
59
|
+
),
|
|
60
|
+
body: (
|
|
61
|
+
font-weight: $weightRegular,
|
|
62
|
+
letter-spacing: sp(0.5),
|
|
63
|
+
font-size: sp(16),
|
|
64
|
+
line-height: sp(24),
|
|
65
|
+
),
|
|
66
|
+
body-2: (
|
|
67
|
+
font-weight: $weightRegular,
|
|
68
|
+
letter-spacing: sp(0.25),
|
|
69
|
+
font-size: sp(14),
|
|
70
|
+
line-height: sp(20),
|
|
71
|
+
),
|
|
72
|
+
button: (
|
|
73
|
+
font-weight: $weightMedium,
|
|
74
|
+
text-transform: uppercase,
|
|
75
|
+
letter-spacing: sp(1.25),
|
|
76
|
+
font-size: sp(14),
|
|
77
|
+
line-height: sp(16),
|
|
78
|
+
),
|
|
79
|
+
caption: (
|
|
80
|
+
font-weight: $weightRegular,
|
|
81
|
+
letter-spacing: sp(0.4),
|
|
82
|
+
font-size: sp(12),
|
|
83
|
+
line-height: sp(16),
|
|
84
|
+
),
|
|
85
|
+
overline: (
|
|
86
|
+
font-weight: $weightRegular,
|
|
87
|
+
letter-spacing: sp(1.5),
|
|
88
|
+
font-size: sp(10),
|
|
89
|
+
line-height: sp(12),
|
|
90
|
+
),
|
|
91
|
+
) !default;
|
|
92
|
+
|
|
93
|
+
@mixin addRules($type) {
|
|
94
|
+
$rules: map.get($types, $type);
|
|
95
|
+
@each $key in map.keys($rules) {
|
|
96
|
+
#{$key}: map.get($rules, $key);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@mixin baselineToTop($dp) {
|
|
101
|
+
&::before {
|
|
102
|
+
content: '';
|
|
103
|
+
|
|
104
|
+
display: inline-block;
|
|
105
|
+
|
|
106
|
+
block-size: dp($dp);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@mixin baselineToBottom($dp) {
|
|
111
|
+
&::after {
|
|
112
|
+
content: '';
|
|
113
|
+
|
|
114
|
+
display: inline-block;
|
|
115
|
+
vertical-align: dp(-$dp);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@mixin textTopToTop($dp) {
|
|
120
|
+
&::before {
|
|
121
|
+
content: "\200B";
|
|
122
|
+
|
|
123
|
+
display: inline-block;
|
|
124
|
+
|
|
125
|
+
block-size: 1em;
|
|
126
|
+
margin-block-start: dp($dp);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -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,49 @@
|
|
|
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
|
+
const buttonElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
12
|
+
if (!buttonElement) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (buttonElement.getAttribute('aria-disabled') === 'true') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
event.stopPropagation();
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
const newEvent = document.createEvent('Event');
|
|
21
|
+
newEvent.initEvent('click', true, true);
|
|
22
|
+
buttonElement.dispatchEvent(newEvent);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Element} element
|
|
27
|
+
* @return {void}
|
|
28
|
+
*/
|
|
29
|
+
export function attach(element) {
|
|
30
|
+
element.setAttribute('role', 'button');
|
|
31
|
+
if (!(element instanceof HTMLButtonElement)
|
|
32
|
+
&& !element.hasAttribute('tabindex')) {
|
|
33
|
+
element.setAttribute('tabindex', '0');
|
|
34
|
+
}
|
|
35
|
+
element.setAttribute('mdw-aria-button-js', '');
|
|
36
|
+
if (!(element instanceof HTMLButtonElement)
|
|
37
|
+
&& !(element instanceof HTMLInputElement)) {
|
|
38
|
+
element.addEventListener('keydown', onKeyDown);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {Element} element
|
|
44
|
+
* @return {void}
|
|
45
|
+
*/
|
|
46
|
+
export function detach(element) {
|
|
47
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
48
|
+
element.removeAttribute('mdw-aria-button-js');
|
|
49
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
const element = /** @type {Element} */ (event.currentTarget);
|
|
22
|
+
const detail = {
|
|
23
|
+
ctrlKey: event.ctrlKey,
|
|
24
|
+
shiftKey: event.shiftKey,
|
|
25
|
+
altKey: event.altKey,
|
|
26
|
+
metaKey: event.metaKey,
|
|
27
|
+
repeat: event.repeat,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let type;
|
|
31
|
+
switch (event.key) {
|
|
32
|
+
case 'Enter':
|
|
33
|
+
type = ENTER_KEY;
|
|
34
|
+
break;
|
|
35
|
+
case ' ':
|
|
36
|
+
case 'Spacebar':
|
|
37
|
+
type = SPACEBAR_KEY;
|
|
38
|
+
break;
|
|
39
|
+
case 'ArrowDown':
|
|
40
|
+
case 'Down':
|
|
41
|
+
type = DOWN_ARROW_KEY;
|
|
42
|
+
break;
|
|
43
|
+
case 'ArrowUp':
|
|
44
|
+
case 'Up':
|
|
45
|
+
type = UP_ARROW_KEY;
|
|
46
|
+
break;
|
|
47
|
+
case 'ArrowLeft':
|
|
48
|
+
case 'Left':
|
|
49
|
+
type = isRtl() ? FORWARD_ARROW_KEY : BACK_ARROW_KEY;
|
|
50
|
+
break;
|
|
51
|
+
case 'ArrowRight':
|
|
52
|
+
case 'Right':
|
|
53
|
+
type = isRtl() ? BACK_ARROW_KEY : FORWARD_ARROW_KEY;
|
|
54
|
+
break;
|
|
55
|
+
case 'Home':
|
|
56
|
+
type = HOME_KEY;
|
|
57
|
+
break;
|
|
58
|
+
case 'End':
|
|
59
|
+
type = END_KEY;
|
|
60
|
+
break;
|
|
61
|
+
case 'PageUp':
|
|
62
|
+
type = PAGEUP_KEY;
|
|
63
|
+
break;
|
|
64
|
+
case 'PageDown':
|
|
65
|
+
type = PAGEDOWN_KEY;
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!dispatchDomEvent(element, type, detail)) {
|
|
72
|
+
// preventDefault called
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {Element} element
|
|
80
|
+
* @return {void}
|
|
81
|
+
*/
|
|
82
|
+
export function attach(element) {
|
|
83
|
+
element.addEventListener('keydown', onKeyDownHandler);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {Element} element
|
|
88
|
+
* @return {void}
|
|
89
|
+
*/
|
|
90
|
+
export function detach(element) {
|
|
91
|
+
element.removeEventListener('keydown', onKeyDownHandler);
|
|
92
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#kbd_roving_tabindex
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
dispatchDomEvent,
|
|
5
|
+
} from '../dom.js';
|
|
6
|
+
|
|
7
|
+
export const TABINDEX_ZEROED = 'mdw:rovingtabindex-tabindexzeroed';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {FocusEvent} event
|
|
11
|
+
* @return {void}
|
|
12
|
+
*/
|
|
13
|
+
function onChildFocus(event) {
|
|
14
|
+
const child = /** @type {Element} */ (event.currentTarget);
|
|
15
|
+
if (child.getAttribute('tabindex') === '0') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
child.setAttribute('tabindex', '0');
|
|
19
|
+
dispatchDomEvent(child, TABINDEX_ZEROED);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {Iterable<Element>} items
|
|
24
|
+
* @param {Element[]} [excludeItems]
|
|
25
|
+
* @return {void}
|
|
26
|
+
*/
|
|
27
|
+
export function removeTabIndex(items, excludeItems = []) {
|
|
28
|
+
for (const item of items) {
|
|
29
|
+
if (excludeItems.includes(item)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (item.hasAttribute('tabindex')) {
|
|
33
|
+
item.setAttribute('tabindex', '-1');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {HTMLElement} element
|
|
40
|
+
* @return {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function attemptFocus(element) {
|
|
43
|
+
try {
|
|
44
|
+
element.focus();
|
|
45
|
+
} catch {
|
|
46
|
+
// Ignore error.
|
|
47
|
+
}
|
|
48
|
+
return document.activeElement === element;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Iterable<HTMLElement>} list
|
|
53
|
+
* @param {Element} [current]
|
|
54
|
+
* @param {boolean} [loop=true]
|
|
55
|
+
* @param {boolean} [reverse]
|
|
56
|
+
* @return {void}
|
|
57
|
+
*/
|
|
58
|
+
export function selectNext(list, current = null, loop = true, reverse = false) {
|
|
59
|
+
let foundCurrent = false;
|
|
60
|
+
|
|
61
|
+
const iterateResult = [...list].some((item, index, array) => {
|
|
62
|
+
const candidate = reverse ? (array[array.length - 1 - index]) : item;
|
|
63
|
+
if (!foundCurrent) {
|
|
64
|
+
if (current) {
|
|
65
|
+
if (candidate === current) {
|
|
66
|
+
foundCurrent = true;
|
|
67
|
+
}
|
|
68
|
+
} else if (candidate.getAttribute('tabindex') === '0') {
|
|
69
|
+
foundCurrent = true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!candidate.hasAttribute('tabindex')) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (candidate.getAttribute('aria-hidden') === 'true') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (candidate.getAttribute('mdw-skip-tab') === 'true') {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return attemptFocus(candidate);
|
|
83
|
+
});
|
|
84
|
+
if (iterateResult) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!loop) {
|
|
88
|
+
if (document.activeElement !== current && current instanceof HTMLElement) {
|
|
89
|
+
current.focus();
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
[...list].some((item, index, array) => {
|
|
94
|
+
const candidate = reverse ? (array[array.length - 1 - index]) : item;
|
|
95
|
+
if (!candidate.hasAttribute('tabindex')) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (candidate.getAttribute('aria-hidden') === 'true') {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (candidate.getAttribute('mdw-skip-tab') === 'true') {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
// Abort if we've looped all the way back to original element
|
|
105
|
+
// Abort if candidate received focus
|
|
106
|
+
return (attemptFocus(candidate) || candidate === current);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Alias for selectNext(list, current, true);
|
|
112
|
+
* @param {Iterable<HTMLElement>} list
|
|
113
|
+
* @param {Element} [current]
|
|
114
|
+
* @param {boolean} [loop=true]
|
|
115
|
+
* @return {void}
|
|
116
|
+
*/
|
|
117
|
+
export function selectPrevious(list, current, loop = true) {
|
|
118
|
+
return selectNext(list, current, loop, true);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {Element} element
|
|
123
|
+
* @return {void}
|
|
124
|
+
*/
|
|
125
|
+
export function attach(element) {
|
|
126
|
+
if (!element.hasAttribute('tabindex')) {
|
|
127
|
+
element.setAttribute('tabindex', (document.activeElement === element) ? '0' : '-1');
|
|
128
|
+
}
|
|
129
|
+
element.addEventListener('focus', onChildFocus);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {Element} element
|
|
134
|
+
* @return {void}
|
|
135
|
+
*/
|
|
136
|
+
export function detach(element) {
|
|
137
|
+
element.removeEventListener('focus', onChildFocus);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {Iterable<Element>} items
|
|
142
|
+
* @param {boolean} [focusableWhenDisabled=true]
|
|
143
|
+
* @return {void}
|
|
144
|
+
*/
|
|
145
|
+
export function setupTabIndexes(items, focusableWhenDisabled = true) {
|
|
146
|
+
/** @type {Element} */
|
|
147
|
+
let currentlyFocusedChild = null;
|
|
148
|
+
/** @type {Element} */
|
|
149
|
+
let currentTabIndexChild = null;
|
|
150
|
+
/** @type {Element} */
|
|
151
|
+
let firstFocusableChild = null;
|
|
152
|
+
for (const child of items) {
|
|
153
|
+
if (!currentlyFocusedChild && document.activeElement === child) {
|
|
154
|
+
currentlyFocusedChild = child;
|
|
155
|
+
} else if (!currentTabIndexChild && child.getAttribute('tabindex') === '0') {
|
|
156
|
+
currentTabIndexChild = child;
|
|
157
|
+
} else {
|
|
158
|
+
if (!firstFocusableChild && child.getAttribute('aria-hidden') !== 'true'
|
|
159
|
+
&& (focusableWhenDisabled || child.getAttribute('aria-disabled') !== 'true')) {
|
|
160
|
+
firstFocusableChild = child;
|
|
161
|
+
}
|
|
162
|
+
child.setAttribute('tabindex', '-1');
|
|
163
|
+
}
|
|
164
|
+
attach(child);
|
|
165
|
+
}
|
|
166
|
+
if (currentlyFocusedChild) {
|
|
167
|
+
currentlyFocusedChild.setAttribute('tabindex', '0');
|
|
168
|
+
} else if (currentTabIndexChild) {
|
|
169
|
+
if (currentlyFocusedChild) {
|
|
170
|
+
currentTabIndexChild.setAttribute('tabindex', '-1');
|
|
171
|
+
}
|
|
172
|
+
} else if (firstFocusableChild) {
|
|
173
|
+
firstFocusableChild.setAttribute('tabindex', '0');
|
|
174
|
+
}
|
|
175
|
+
}
|
package/core/aria/tab.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
const element = /** @type {HTMLElement} */ (event.currentTarget);
|
|
30
|
+
if (!element) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
event.stopPropagation();
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
const newEvent = document.createEvent('Event');
|
|
36
|
+
newEvent.initEvent('click', true, true);
|
|
37
|
+
element.dispatchEvent(newEvent);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Element} element
|
|
42
|
+
* @return {void}
|
|
43
|
+
*/
|
|
44
|
+
export function attach(element) {
|
|
45
|
+
element.setAttribute('role', 'tab');
|
|
46
|
+
element.setAttribute('mdw-aria-tab-js', '');
|
|
47
|
+
element.addEventListener('keydown', onKeyDown);
|
|
48
|
+
Keyboard.attach(element);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Element} element
|
|
53
|
+
* @return {void}
|
|
54
|
+
*/
|
|
55
|
+
export function detach(element) {
|
|
56
|
+
Keyboard.detach(element);
|
|
57
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
58
|
+
element.removeAttribute('mdw-aria-tab-js');
|
|
59
|
+
}
|