/
SegmentedButtonGroup.js
69 lines (59 loc) · 1.58 KB
/
SegmentedButtonGroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import KeyboardNav from '../mixins/KeyboardNavMixin.js';
import Box from './Box.js';
import SegmentedButton from './SegmentedButton.js';
/** @typedef {'compact'} DeprecatedHTMLMenuElementProperties */
export default Box
.extend()
.mixin(KeyboardNav)
.define({
kbdNavQuery() {
return SegmentedButton.elementName;
},
})
.set({
_ariaRole: 'listbox',
})
.childEvents({
slot: {
slotchange() {
this.refreshTabIndexes();
const list = /** @type {NodeListOf<InstanceType<SegmentedButton>>} */ (this.kbdNavChildren);
for (const [index, child] of list.entries()) {
child.shapeStart = index === 0;
child.innerSegmentedButton = index > 0 && index < list.length - 1;
child.shapeEnd = index === list.length - 1;
}
},
},
})
.css`
/* https://m3.material.io/components/segmented-buttons/specs */
:host {
--mdw-bg: var(--mdw-color__secondary-container);
--mdw-ink: var(--mdw-color__on-secondary-container);
display: inline-flex;
align-items: stretch;
flex-direction: row;
justify-content: initial;
overflow-x: auto;
overflow-y: hidden;
box-sizing: border-box;
min-inline-size: 100%;
flex:none;
}
:host([color]) {
background-color: transparent;
}
#slot {
display: grid;
grid-auto-columns: 1fr;
grid-auto-flow: column;
flex: none;
}
`
.on({
constructed() {
this.updateAriaProperty('ariaOrientation', 'horizontal');
},
})
.autoRegister('mdw-segmented-button-group');