@spectrum-web-components/radio 0.9.3-express.0 → 0.9.5
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/custom-elements.json +15 -41
- package/package.json +8 -7
- package/src/Radio.d.ts +0 -2
- package/src/Radio.js +1 -16
- package/src/Radio.js.map +1 -1
- package/src/RadioGroup.d.ts +3 -4
- package/src/RadioGroup.js +20 -119
- package/src/RadioGroup.js.map +1 -1
package/custom-elements.json
CHANGED
|
@@ -124,14 +124,6 @@
|
|
|
124
124
|
"attribute": "readonly",
|
|
125
125
|
"reflects": true
|
|
126
126
|
},
|
|
127
|
-
{
|
|
128
|
-
"kind": "field",
|
|
129
|
-
"name": "inputElement",
|
|
130
|
-
"type": {
|
|
131
|
-
"text": "HTMLInputElement"
|
|
132
|
-
},
|
|
133
|
-
"privacy": "private"
|
|
134
|
-
},
|
|
135
127
|
{
|
|
136
128
|
"kind": "method",
|
|
137
129
|
"name": "click",
|
|
@@ -152,24 +144,6 @@
|
|
|
152
144
|
}
|
|
153
145
|
}
|
|
154
146
|
},
|
|
155
|
-
{
|
|
156
|
-
"kind": "method",
|
|
157
|
-
"name": "handleChange",
|
|
158
|
-
"privacy": "public",
|
|
159
|
-
"return": {
|
|
160
|
-
"type": {
|
|
161
|
-
"text": "void"
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
"parameters": [
|
|
165
|
-
{
|
|
166
|
-
"name": "event",
|
|
167
|
-
"type": {
|
|
168
|
-
"text": "Event"
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
},
|
|
173
147
|
{
|
|
174
148
|
"kind": "method",
|
|
175
149
|
"name": "activate",
|
|
@@ -356,6 +330,11 @@
|
|
|
356
330
|
},
|
|
357
331
|
"privacy": "public"
|
|
358
332
|
},
|
|
333
|
+
{
|
|
334
|
+
"kind": "field",
|
|
335
|
+
"name": "rovingTabindexController",
|
|
336
|
+
"default": "new RovingTabindexController<Radio>(this, {\n focusInIndex: (elements: Radio[]) => {\n return elements.findIndex((el) => {\n return this.selected\n ? !el.disabled && el.value === this.selected\n : !el.disabled;\n });\n },\n elementEnterAction: (el: Radio) => {\n this.selected = el.value;\n },\n elements: () => this.buttons,\n isFocusableElement: (el: Radio) => !el.disabled,\n })"
|
|
337
|
+
},
|
|
359
338
|
{
|
|
360
339
|
"kind": "method",
|
|
361
340
|
"name": "focus",
|
|
@@ -366,21 +345,6 @@
|
|
|
366
345
|
}
|
|
367
346
|
}
|
|
368
347
|
},
|
|
369
|
-
{
|
|
370
|
-
"kind": "field",
|
|
371
|
-
"name": "handleFocusin",
|
|
372
|
-
"privacy": "private"
|
|
373
|
-
},
|
|
374
|
-
{
|
|
375
|
-
"kind": "field",
|
|
376
|
-
"name": "handleKeydown",
|
|
377
|
-
"privacy": "private"
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
"kind": "field",
|
|
381
|
-
"name": "handleFocusout",
|
|
382
|
-
"privacy": "private"
|
|
383
|
-
},
|
|
384
348
|
{
|
|
385
349
|
"kind": "method",
|
|
386
350
|
"name": "_setSelected",
|
|
@@ -419,6 +383,16 @@
|
|
|
419
383
|
"text": "void"
|
|
420
384
|
}
|
|
421
385
|
}
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"kind": "method",
|
|
389
|
+
"name": "handleSlotchange",
|
|
390
|
+
"privacy": "protected",
|
|
391
|
+
"return": {
|
|
392
|
+
"type": {
|
|
393
|
+
"text": "void"
|
|
394
|
+
}
|
|
395
|
+
}
|
|
422
396
|
}
|
|
423
397
|
],
|
|
424
398
|
"events": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/radio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,19 +46,20 @@
|
|
|
46
46
|
"lit-html"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@spectrum-web-components/base": "^0.5.2
|
|
50
|
-
"@spectrum-web-components/field-group": "^0.5.
|
|
51
|
-
"@spectrum-web-components/help-text": "^0.1.
|
|
52
|
-
"@spectrum-web-components/
|
|
49
|
+
"@spectrum-web-components/base": "^0.5.2",
|
|
50
|
+
"@spectrum-web-components/field-group": "^0.5.3",
|
|
51
|
+
"@spectrum-web-components/help-text": "^0.1.2",
|
|
52
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.0",
|
|
53
|
+
"@spectrum-web-components/shared": "^0.13.4",
|
|
53
54
|
"tslib": "^2.0.0"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@spectrum-css/radio": "
|
|
57
|
+
"@spectrum-css/radio": "^3.0.12"
|
|
57
58
|
},
|
|
58
59
|
"types": "./src/index.d.ts",
|
|
59
60
|
"customElements": "custom-elements.json",
|
|
60
61
|
"sideEffects": [
|
|
61
62
|
"./sp-*.js"
|
|
62
63
|
],
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "bb5308b9be01cc7c5bbab289312042256bdcc740"
|
|
64
65
|
}
|
package/src/Radio.d.ts
CHANGED
|
@@ -25,10 +25,8 @@ export declare class Radio extends Radio_base {
|
|
|
25
25
|
emphasized: boolean;
|
|
26
26
|
invalid: boolean;
|
|
27
27
|
readonly: boolean;
|
|
28
|
-
private inputElement;
|
|
29
28
|
click(): void;
|
|
30
29
|
protected manageAutoFocus(): void;
|
|
31
|
-
handleChange(event: Event): void;
|
|
32
30
|
protected activate(): void;
|
|
33
31
|
protected handleKeyup(event: KeyboardEvent): void;
|
|
34
32
|
protected render(): TemplateResult;
|
package/src/Radio.js
CHANGED
|
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
import { __decorate } from "tslib";
|
|
13
13
|
import { html, SpectrumElement, } from '@spectrum-web-components/base';
|
|
14
|
-
import { property
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
15
|
import { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';
|
|
16
16
|
import radioStyles from './radio.css.js';
|
|
17
17
|
/**
|
|
@@ -63,18 +63,6 @@ export class Radio extends FocusVisiblePolyfillMixin(SpectrumElement) {
|
|
|
63
63
|
this.focus();
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
handleChange(event) {
|
|
67
|
-
event.stopPropagation();
|
|
68
|
-
if (this.readonly) {
|
|
69
|
-
this.inputElement.checked = this.checked;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.checked = this.inputElement.checked;
|
|
73
|
-
this.dispatchEvent(new Event('change', {
|
|
74
|
-
bubbles: true,
|
|
75
|
-
composed: true,
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
66
|
activate() {
|
|
79
67
|
this.checked = true;
|
|
80
68
|
this.dispatchEvent(new Event('change', {
|
|
@@ -153,7 +141,4 @@ __decorate([
|
|
|
153
141
|
__decorate([
|
|
154
142
|
property({ type: Boolean, reflect: true })
|
|
155
143
|
], Radio.prototype, "readonly", void 0);
|
|
156
|
-
__decorate([
|
|
157
|
-
query('#input')
|
|
158
|
-
], Radio.prototype, "inputElement", void 0);
|
|
159
144
|
//# sourceMappingURL=Radio.js.map
|
package/src/Radio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Radio.js","sourceRoot":"","sources":["Radio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"Radio.js","sourceRoot":"","sources":["Radio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CA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;aACzC;SACJ;IACL,CAAC;CACJ;AAtGG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;wCACH;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCACxB;AAGlB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sCACpB;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uCACnB;AAGxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yCACjB;AAG1B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sCACpB;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uCACnB","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\n\nimport radioStyles from './radio.css.js';\n\n/**\n * @element sp-radio\n *\n * @slot - text label of the Radio button\n * @attr label-below - Moves the label below the radio button\n * @attr invalid - Uses the invalid style\n * @attr disabled - Uses the disabled style\n * @attr checked - Represents when the input is checked\n * @attr value - Identifies this radio button within its radio group\n *\n * @fires change - When the input is interacted with and its state is changed\n */\nexport class Radio extends FocusVisiblePolyfillMixin(SpectrumElement) {\n public static get styles(): CSSResultArray {\n return [radioStyles];\n }\n\n /**\n * When this control is rendered, focus it automatically\n * @private\n */\n @property({ type: Boolean })\n public autofocus = false;\n\n @property({ type: String, reflect: true })\n public value = '';\n\n @property({ type: Boolean, reflect: true })\n public checked = false;\n\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true })\n public invalid = false;\n\n @property({ type: Boolean, reflect: true })\n public readonly = false;\n\n public click(): void {\n if (this.disabled) {\n return;\n }\n this.activate();\n }\n\n protected manageAutoFocus(): void {\n if (this.autofocus) {\n /**\n * Trick :focus-visible polyfill into thinking keyboard based focus\n *\n * @private\n **/\n this.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'Tab',\n })\n );\n this.focus();\n }\n }\n\n protected activate(): void {\n this.checked = true;\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n protected handleKeyup(event: KeyboardEvent): void {\n if (event.code === 'Space') {\n this.activate();\n }\n }\n\n protected render(): TemplateResult {\n return html`\n <div id=\"input\"></div>\n <span id=\"button\"></span>\n <span id=\"label\" role=\"presentation\"><slot></slot></span>\n `;\n }\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n this.setAttribute('role', 'radio');\n if (!this.hasAttribute('tabindex')) {\n this.tabIndex = 0;\n }\n this.manageAutoFocus();\n this.addEventListener('click', this.activate);\n this.addEventListener('keyup', this.handleKeyup);\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n if (changes.has('invalid')) {\n if (this.invalid) {\n this.setAttribute('aria-invalid', 'true');\n } else {\n this.removeAttribute('aria-invalid');\n }\n }\n if (changes.has('checked')) {\n if (this.checked) {\n this.setAttribute('aria-checked', 'true');\n } else {\n this.setAttribute('aria-checked', 'false');\n }\n }\n if (changes.has('disabled')) {\n if (this.disabled) {\n this.setAttribute('aria-disabled', 'true');\n } else {\n this.removeAttribute('aria-disabeld');\n }\n }\n }\n}\n"]}
|
package/src/RadioGroup.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PropertyValues } from '@spectrum-web-components/base';
|
|
2
2
|
import { FieldGroup } from '@spectrum-web-components/field-group';
|
|
3
3
|
import { Radio } from './Radio.js';
|
|
4
|
+
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
4
5
|
declare const RadioGroup_base: typeof FieldGroup;
|
|
5
6
|
/**
|
|
6
7
|
* @element sp-radio-group
|
|
@@ -15,15 +16,13 @@ export declare class RadioGroup extends RadioGroup_base {
|
|
|
15
16
|
name: string;
|
|
16
17
|
defaultNodes: Node[];
|
|
17
18
|
get buttons(): Radio[];
|
|
18
|
-
|
|
19
|
+
rovingTabindexController: RovingTabindexController<Radio>;
|
|
19
20
|
focus(): void;
|
|
20
|
-
private handleFocusin;
|
|
21
|
-
private handleKeydown;
|
|
22
|
-
private handleFocusout;
|
|
23
21
|
private _setSelected;
|
|
24
22
|
selected: string;
|
|
25
23
|
protected firstUpdated(changes: PropertyValues<this>): void;
|
|
26
24
|
protected updated(changes: PropertyValues<this>): void;
|
|
27
25
|
private validateRadios;
|
|
26
|
+
protected handleSlotchange(): void;
|
|
28
27
|
}
|
|
29
28
|
export {};
|
package/src/RadioGroup.js
CHANGED
|
@@ -14,6 +14,7 @@ import { property, queryAssignedNodes, } from '@spectrum-web-components/base/src
|
|
|
14
14
|
import { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';
|
|
15
15
|
import { FieldGroup } from '@spectrum-web-components/field-group';
|
|
16
16
|
import { Radio } from './Radio.js';
|
|
17
|
+
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
17
18
|
/**
|
|
18
19
|
* @element sp-radio-group
|
|
19
20
|
*
|
|
@@ -25,122 +26,29 @@ import { Radio } from './Radio.js';
|
|
|
25
26
|
*/
|
|
26
27
|
export class RadioGroup extends FocusVisiblePolyfillMixin(FieldGroup) {
|
|
27
28
|
constructor() {
|
|
28
|
-
super();
|
|
29
|
+
super(...arguments);
|
|
29
30
|
this.name = '';
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/* c8 ignore next 3 */
|
|
45
|
-
if (!activeElement) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
let nextIndex = this.buttons.indexOf(activeElement);
|
|
49
|
-
/* c8 ignore next 3 */
|
|
50
|
-
if (nextIndex === -1) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const circularIndexedElement = (list, index) => list[(list.length + index) % list.length];
|
|
54
|
-
const buttonFromDelta = (delta) => {
|
|
55
|
-
nextIndex += delta;
|
|
56
|
-
while (circularIndexedElement(this.buttons, nextIndex).disabled) {
|
|
57
|
-
nextIndex += delta;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
switch (code) {
|
|
61
|
-
case 'ArrowUp':
|
|
62
|
-
buttonFromDelta(-1);
|
|
63
|
-
break;
|
|
64
|
-
case 'ArrowLeft':
|
|
65
|
-
buttonFromDelta(this.isLTR ? -1 : 1);
|
|
66
|
-
break;
|
|
67
|
-
case 'ArrowRight':
|
|
68
|
-
buttonFromDelta(this.isLTR ? 1 : -1);
|
|
69
|
-
break;
|
|
70
|
-
case 'ArrowDown':
|
|
71
|
-
buttonFromDelta(1);
|
|
72
|
-
break;
|
|
73
|
-
case 'End':
|
|
74
|
-
nextIndex = this.buttons.length;
|
|
75
|
-
buttonFromDelta(-1);
|
|
76
|
-
break;
|
|
77
|
-
case 'Home':
|
|
78
|
-
nextIndex = -1;
|
|
79
|
-
buttonFromDelta(1);
|
|
80
|
-
break;
|
|
81
|
-
case 'PageUp':
|
|
82
|
-
case 'PageDown':
|
|
83
|
-
const tagsSiblings = [
|
|
84
|
-
...this.getRootNode().querySelectorAll('sp-radio-group'),
|
|
85
|
-
];
|
|
86
|
-
if (tagsSiblings.length < 2) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
event.preventDefault();
|
|
90
|
-
const currentIndex = tagsSiblings.indexOf(this);
|
|
91
|
-
const offset = code === 'PageUp' ? -1 : 1;
|
|
92
|
-
let nextRadioGroupIndex = currentIndex + offset;
|
|
93
|
-
let nextRadioGroup = circularIndexedElement(tagsSiblings, nextRadioGroupIndex);
|
|
94
|
-
while (!nextRadioGroup.buttons.length) {
|
|
95
|
-
nextRadioGroupIndex += offset;
|
|
96
|
-
nextRadioGroup = circularIndexedElement(tagsSiblings, nextRadioGroupIndex);
|
|
97
|
-
}
|
|
98
|
-
nextRadioGroup.focus();
|
|
99
|
-
return;
|
|
100
|
-
default:
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
event.preventDefault();
|
|
104
|
-
const nextRadio = circularIndexedElement(this.buttons, nextIndex);
|
|
105
|
-
this._setSelected(nextRadio.value);
|
|
106
|
-
nextRadio.focus();
|
|
107
|
-
};
|
|
108
|
-
this.handleFocusout = (event) => {
|
|
109
|
-
const nextActiveElement = event.relatedTarget;
|
|
110
|
-
if (nextActiveElement && this.contains(nextActiveElement)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const firstButtonNonDisabled = this.buttons.find((button) => {
|
|
114
|
-
if (this.selected) {
|
|
115
|
-
return button.checked;
|
|
116
|
-
}
|
|
117
|
-
return !button.disabled;
|
|
118
|
-
});
|
|
119
|
-
if (firstButtonNonDisabled) {
|
|
120
|
-
firstButtonNonDisabled.tabIndex = 0;
|
|
121
|
-
}
|
|
122
|
-
this.removeEventListener('keydown', this.handleKeydown);
|
|
123
|
-
this.removeEventListener('focusout', this.handleFocusout);
|
|
124
|
-
};
|
|
31
|
+
this.rovingTabindexController = new RovingTabindexController(this, {
|
|
32
|
+
focusInIndex: (elements) => {
|
|
33
|
+
return elements.findIndex((el) => {
|
|
34
|
+
return this.selected
|
|
35
|
+
? !el.disabled && el.value === this.selected
|
|
36
|
+
: !el.disabled;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
elementEnterAction: (el) => {
|
|
40
|
+
this.selected = el.value;
|
|
41
|
+
},
|
|
42
|
+
elements: () => this.buttons,
|
|
43
|
+
isFocusableElement: (el) => !el.disabled,
|
|
44
|
+
});
|
|
125
45
|
this.selected = '';
|
|
126
|
-
this.addEventListener('focusin', this.handleFocusin);
|
|
127
46
|
}
|
|
128
47
|
get buttons() {
|
|
129
48
|
return this.defaultNodes.filter((node) => node instanceof Radio);
|
|
130
49
|
}
|
|
131
50
|
focus() {
|
|
132
|
-
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const firstButtonNonDisabled = this.buttons.find((button) => {
|
|
136
|
-
if (this.selected) {
|
|
137
|
-
return button.checked;
|
|
138
|
-
}
|
|
139
|
-
return !button.disabled;
|
|
140
|
-
});
|
|
141
|
-
if (firstButtonNonDisabled) {
|
|
142
|
-
firstButtonNonDisabled.focus();
|
|
143
|
-
}
|
|
51
|
+
this.rovingTabindexController.focus();
|
|
144
52
|
}
|
|
145
53
|
_setSelected(value) {
|
|
146
54
|
if (value === this.selected) {
|
|
@@ -188,16 +96,6 @@ export class RadioGroup extends FocusVisiblePolyfillMixin(FieldGroup) {
|
|
|
188
96
|
const target = event.target;
|
|
189
97
|
this._setSelected(target.value);
|
|
190
98
|
});
|
|
191
|
-
this.buttons.map((button, index) => {
|
|
192
|
-
const focusable = this.selected
|
|
193
|
-
? !button.disabled && button.value === this.selected
|
|
194
|
-
? '0'
|
|
195
|
-
: '-1'
|
|
196
|
-
: !button.disabled && index === 0
|
|
197
|
-
? '0'
|
|
198
|
-
: '-1';
|
|
199
|
-
button.setAttribute('tabindex', focusable);
|
|
200
|
-
});
|
|
201
99
|
}
|
|
202
100
|
updated(changes) {
|
|
203
101
|
super.updated(changes);
|
|
@@ -215,6 +113,9 @@ export class RadioGroup extends FocusVisiblePolyfillMixin(FieldGroup) {
|
|
|
215
113
|
this.selected = '';
|
|
216
114
|
}
|
|
217
115
|
}
|
|
116
|
+
handleSlotchange() {
|
|
117
|
+
this.rovingTabindexController.clearElementCache();
|
|
118
|
+
}
|
|
218
119
|
}
|
|
219
120
|
__decorate([
|
|
220
121
|
property({ type: String })
|
package/src/RadioGroup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["RadioGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAGF,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAW,SAAQ,yBAAyB,CAAC,UAAU,CAAC;IAajE;QACI,KAAK,EAAE,CAAC;QAZL,SAAI,GAAG,EAAE,CAAC;QA+BT,kBAAa,GAAG,GAAS,EAAE;YAC/B,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACvD,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACrD,qBAAqB,CAAC,GAAG,EAAE;gBACvB,MAAM,uBAAuB,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAC7C,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,C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,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,CAAC,cAAc,EAAE,CAAC;SACzB;IACL,CAAC;IAEO,cAAc;QAClB,IAAI,cAAc,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACxB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC;YAChD,cAAc,GAAG,cAAc,IAAI,MAAM,CAAC,OAAO,CAAC;QACtD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;SACtB;IACL,CAAC;CACJ;AAlOG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCACV;AAGjB;IADC,kBAAkB,CAAC,EAAE,CAAC;gDACM;AAqK7B;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CACP","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { PropertyValues } from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\nimport { FieldGroup } from '@spectrum-web-components/field-group';\n\nimport { Radio } from './Radio.js';\n\n/**\n * @element sp-radio-group\n *\n * @slot - The `sp-radio` elements to display/manage in the group.\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires change - An alteration to the value of the element has been committed by the user.\n */\nexport class RadioGroup extends FocusVisiblePolyfillMixin(FieldGroup) {\n @property({ type: String })\n public name = '';\n\n @queryAssignedNodes('')\n public defaultNodes!: Node[];\n\n public get buttons(): Radio[] {\n return this.defaultNodes.filter(\n (node) => (node as HTMLElement) instanceof Radio\n ) as Radio[];\n }\n\n constructor() {\n super();\n this.addEventListener('focusin', this.handleFocusin);\n }\n\n public focus(): void {\n if (!this.buttons.length) {\n return;\n }\n const firstButtonNonDisabled = this.buttons.find((button) => {\n if (this.selected) {\n return button.checked;\n }\n return !button.disabled;\n });\n if (firstButtonNonDisabled) {\n firstButtonNonDisabled.focus();\n }\n }\n\n private handleFocusin = (): void => {\n this.addEventListener('focusout', this.handleFocusout);\n this.addEventListener('keydown', this.handleKeydown);\n requestAnimationFrame(() => {\n const firstButtonWithTabIndex = this.buttons.find(\n (button) => button.tabIndex === 0\n );\n if (firstButtonWithTabIndex) {\n firstButtonWithTabIndex.tabIndex = -1;\n }\n });\n };\n\n private handleKeydown = (event: KeyboardEvent): void => {\n const { code } = event;\n const activeElement = (this.getRootNode() as Document)\n .activeElement as Radio;\n /* c8 ignore next 3 */\n if (!activeElement) {\n return;\n }\n let nextIndex = this.buttons.indexOf(activeElement);\n /* c8 ignore next 3 */\n if (nextIndex === -1) {\n return;\n }\n const circularIndexedElement = <T extends HTMLElement>(\n list: T[],\n index: number\n ): T => list[(list.length + index) % list.length];\n const buttonFromDelta = (delta: number): void => {\n nextIndex += delta;\n while (circularIndexedElement(this.buttons, nextIndex).disabled) {\n nextIndex += delta;\n }\n };\n switch (code) {\n case 'ArrowUp':\n buttonFromDelta(-1);\n break;\n case 'ArrowLeft':\n buttonFromDelta(this.isLTR ? -1 : 1);\n break;\n case 'ArrowRight':\n buttonFromDelta(this.isLTR ? 1 : -1);\n break;\n case 'ArrowDown':\n buttonFromDelta(1);\n break;\n case 'End':\n nextIndex = this.buttons.length;\n buttonFromDelta(-1);\n break;\n case 'Home':\n nextIndex = -1;\n buttonFromDelta(1);\n break;\n case 'PageUp':\n case 'PageDown':\n const tagsSiblings = [\n ...(\n this.getRootNode() as Document\n ).querySelectorAll<RadioGroup>('sp-radio-group'),\n ];\n if (tagsSiblings.length < 2) {\n return;\n }\n event.preventDefault();\n const currentIndex = tagsSiblings.indexOf(this);\n const offset = code === 'PageUp' ? -1 : 1;\n let nextRadioGroupIndex = currentIndex + offset;\n let nextRadioGroup = circularIndexedElement(\n tagsSiblings,\n nextRadioGroupIndex\n );\n while (!nextRadioGroup.buttons.length) {\n nextRadioGroupIndex += offset;\n nextRadioGroup = circularIndexedElement(\n tagsSiblings,\n nextRadioGroupIndex\n );\n }\n nextRadioGroup.focus();\n return;\n default:\n return;\n }\n event.preventDefault();\n const nextRadio = circularIndexedElement(this.buttons, nextIndex);\n this._setSelected(nextRadio.value);\n nextRadio.focus();\n };\n\n private handleFocusout = (event: FocusEvent): void => {\n const nextActiveElement = event.relatedTarget as Node;\n if (nextActiveElement && this.contains(nextActiveElement)) {\n return;\n }\n const firstButtonNonDisabled = this.buttons.find((button) => {\n if (this.selected) {\n return button.checked;\n }\n return !button.disabled;\n });\n if (firstButtonNonDisabled) {\n firstButtonNonDisabled.tabIndex = 0;\n }\n this.removeEventListener('keydown', this.handleKeydown);\n this.removeEventListener('focusout', this.handleFocusout);\n };\n\n private _setSelected(value: string): void {\n if (value === this.selected) {\n return;\n }\n const oldValue = this.selected;\n const radio = value\n ? (this.querySelector(`sp-radio[value=\"${value}\"]`) as Radio)\n : undefined;\n\n // If no matching radio, selected is reset to empty string\n this.selected = radio ? value : '';\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n bubbles: true,\n composed: true,\n })\n );\n if (!applyDefault) {\n this.selected = oldValue;\n return;\n }\n this.validateRadios();\n }\n\n @property({ reflect: true })\n public selected = '';\n\n protected firstUpdated(changes: PropertyValues<this>): void {\n super.firstUpdated(changes);\n this.setAttribute('role', 'radiogroup');\n const checkedRadio = this.querySelector('sp-radio[checked]') as Radio;\n const checkedRadioValue = checkedRadio ? checkedRadio.value : '';\n // Prefer the checked item over the selected value\n this.selected = checkedRadioValue || this.selected;\n // Validate the selected value is actual a radio option\n if (this.selected && this.selected !== checkedRadioValue) {\n const selectedRadio = this.querySelector(\n `sp-radio[value=\"${this.selected}\"]`\n ) as Radio;\n if (!selectedRadio) {\n this.selected = '';\n } else {\n selectedRadio.checked = true;\n }\n }\n\n this.addEventListener('change', (event: Event) => {\n if (event.target === this) {\n return;\n }\n event.stopPropagation();\n const target = event.target as Radio;\n this._setSelected(target.value);\n });\n this.buttons.map((button, index) => {\n const focusable = this.selected\n ? !button.disabled && button.value === this.selected\n ? '0'\n : '-1'\n : !button.disabled && index === 0\n ? '0'\n : '-1';\n button.setAttribute('tabindex', focusable);\n });\n }\n\n protected updated(changes: PropertyValues<this>): void {\n super.updated(changes);\n if (changes.has('selected')) {\n this.validateRadios();\n }\n }\n\n private validateRadios(): void {\n let validSelection = false;\n this.buttons.map((button) => {\n button.checked = this.selected === button.value;\n validSelection = validSelection || button.checked;\n });\n if (!validSelection) {\n this.selected = '';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["RadioGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAGF,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qEAAqE,CAAC;AAE/G;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAW,SAAQ,yBAAyB,CAAC,UAAU,CAAC;I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BACvB,OAAO;aACV;YACD,KAAK,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAe,CAAC;YACrC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;IAES,OAAO,CAAC,OAA6B;QAC3C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,CAAC,cAAc,EAAE,CAAC;SACzB;IACL,CAAC;IAEO,cAAc;QAClB,IAAI,cAAc,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACxB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC;YAChD,cAAc,GAAG,cAAc,IAAI,MAAM,CAAC,OAAO,CAAC;QACtD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;SACtB;IACL,CAAC;IAES,gBAAgB;QACtB,IAAI,CAAC,wBAAwB,CAAC,iBAAiB,EAAE,CAAC;IACtD,CAAC;CACJ;AA5GG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCACV;AAGjB;IADC,kBAAkB,CAAC,EAAE,CAAC;gDACM;AAqD7B;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CACP","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { PropertyValues } from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\nimport { FieldGroup } from '@spectrum-web-components/field-group';\n\nimport { Radio } from './Radio.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\n\n/**\n * @element sp-radio-group\n *\n * @slot - The `sp-radio` elements to display/manage in the group.\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires change - An alteration to the value of the element has been committed by the user.\n */\nexport class RadioGroup extends FocusVisiblePolyfillMixin(FieldGroup) {\n @property({ type: String })\n public name = '';\n\n @queryAssignedNodes('')\n public defaultNodes!: Node[];\n\n public get buttons(): Radio[] {\n return this.defaultNodes.filter(\n (node) => (node as HTMLElement) instanceof Radio\n ) as Radio[];\n }\n\n rovingTabindexController = new RovingTabindexController<Radio>(this, {\n focusInIndex: (elements: Radio[]) => {\n return elements.findIndex((el) => {\n return this.selected\n ? !el.disabled && el.value === this.selected\n : !el.disabled;\n });\n },\n elementEnterAction: (el: Radio) => {\n this.selected = el.value;\n },\n elements: () => this.buttons,\n isFocusableElement: (el: Radio) => !el.disabled,\n });\n\n public focus(): void {\n this.rovingTabindexController.focus();\n }\n\n private _setSelected(value: string): void {\n if (value === this.selected) {\n return;\n }\n const oldValue = this.selected;\n const radio = value\n ? (this.querySelector(`sp-radio[value=\"${value}\"]`) as Radio)\n : undefined;\n\n // If no matching radio, selected is reset to empty string\n this.selected = radio ? value : '';\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n bubbles: true,\n composed: true,\n })\n );\n if (!applyDefault) {\n this.selected = oldValue;\n return;\n }\n this.validateRadios();\n }\n\n @property({ reflect: true })\n public selected = '';\n\n protected firstUpdated(changes: PropertyValues<this>): void {\n super.firstUpdated(changes);\n this.setAttribute('role', 'radiogroup');\n const checkedRadio = this.querySelector('sp-radio[checked]') as Radio;\n const checkedRadioValue = checkedRadio ? checkedRadio.value : '';\n // Prefer the checked item over the selected value\n this.selected = checkedRadioValue || this.selected;\n // Validate the selected value is actual a radio option\n if (this.selected && this.selected !== checkedRadioValue) {\n const selectedRadio = this.querySelector(\n `sp-radio[value=\"${this.selected}\"]`\n ) as Radio;\n if (!selectedRadio) {\n this.selected = '';\n } else {\n selectedRadio.checked = true;\n }\n }\n\n this.addEventListener('change', (event: Event) => {\n if (event.target === this) {\n return;\n }\n event.stopPropagation();\n const target = event.target as Radio;\n this._setSelected(target.value);\n });\n }\n\n protected updated(changes: PropertyValues<this>): void {\n super.updated(changes);\n if (changes.has('selected')) {\n this.validateRadios();\n }\n }\n\n private validateRadios(): void {\n let validSelection = false;\n this.buttons.map((button) => {\n button.checked = this.selected === button.value;\n validSelection = validSelection || button.checked;\n });\n if (!validSelection) {\n this.selected = '';\n }\n }\n\n protected handleSlotchange(): void {\n this.rovingTabindexController.clearElementCache();\n }\n}\n"]}
|