@spectrum-web-components/radio 0.10.0-devmode.0 → 0.10.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/package.json +7 -7
- package/sp-radio-group.js +1 -2
- package/sp-radio-group.js.map +1 -1
- package/sp-radio.js +1 -2
- package/sp-radio.js.map +1 -1
- package/src/Radio.js +2 -121
- package/src/Radio.js.map +1 -1
- package/src/RadioGroup.js +1 -111
- package/src/RadioGroup.js.map +1 -1
- package/src/index.js +1 -2
- package/src/index.js.map +1 -1
- package/src/radio.css.js +2 -4
- package/src/radio.css.js.map +1 -1
- package/src/spectrum-radio.css.js +2 -4
- package/src/spectrum-radio.css.js.map +1 -1
- package/stories/radio.stories.js +16 -129
- package/stories/radio.stories.js.map +1 -1
- package/test/benchmark/test-basic.js +1 -5
- package/test/benchmark/test-basic.js.map +1 -1
- package/test/radio-group.test.js +18 -324
- package/test/radio-group.test.js.map +1 -1
- package/test/radio.test-vrt.js +1 -3
- package/test/radio.test-vrt.js.map +1 -1
- package/test/radio.test.js +5 -134
- package/test/radio.test.js.map +1 -1
package/stories/radio.stories.js
CHANGED
|
@@ -1,139 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
argTypes: {
|
|
9
|
-
checked: {
|
|
10
|
-
name: "checked",
|
|
11
|
-
type: { name: "boolean", required: false },
|
|
12
|
-
description: "Represents when the input is checked",
|
|
13
|
-
table: {
|
|
14
|
-
type: { summary: "boolean" },
|
|
15
|
-
defaultValue: { summary: false }
|
|
16
|
-
},
|
|
17
|
-
control: "boolean"
|
|
18
|
-
},
|
|
19
|
-
disabled: {
|
|
20
|
-
name: "disabled",
|
|
21
|
-
type: { name: "boolean", required: false },
|
|
22
|
-
description: "Disable this control. It will not receive focus or events.",
|
|
23
|
-
table: {
|
|
24
|
-
type: { summary: "boolean" },
|
|
25
|
-
defaultValue: { summary: false }
|
|
26
|
-
},
|
|
27
|
-
control: {
|
|
28
|
-
type: "boolean"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
emphasized: {
|
|
32
|
-
name: "emphasized",
|
|
33
|
-
type: { name: "boolean", required: false },
|
|
34
|
-
description: "Set the button's state to emphasized.",
|
|
35
|
-
table: {
|
|
36
|
-
type: { summary: "boolean" },
|
|
37
|
-
defaultValue: { summary: false }
|
|
38
|
-
},
|
|
39
|
-
control: {
|
|
40
|
-
type: "boolean"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
invalid: {
|
|
44
|
-
name: "invalid",
|
|
45
|
-
type: { name: "boolean", required: false },
|
|
46
|
-
table: {
|
|
47
|
-
type: { summary: "boolean" },
|
|
48
|
-
defaultValue: { summary: false }
|
|
49
|
-
},
|
|
50
|
-
control: {
|
|
51
|
-
type: "boolean"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
args: {
|
|
56
|
-
checked: false,
|
|
57
|
-
disabled: false,
|
|
58
|
-
emphasized: false,
|
|
59
|
-
invalid: false
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
function renderRadio(args) {
|
|
63
|
-
return html`
|
|
64
|
-
<sp-radio ${spreadProps(args)}>Radio</sp-radio>
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
export const Default = (args) => renderRadio(args);
|
|
68
|
-
export const readonly = (args) => renderRadio({
|
|
69
|
-
...args,
|
|
70
|
-
readonly: true
|
|
71
|
-
});
|
|
72
|
-
readonly.args = {
|
|
73
|
-
checked: true
|
|
74
|
-
};
|
|
75
|
-
export const Emphasized = (args) => renderRadio(args);
|
|
76
|
-
Emphasized.args = {
|
|
77
|
-
checked: true,
|
|
78
|
-
emphasized: true
|
|
79
|
-
};
|
|
80
|
-
export const Autofocus = (args) => {
|
|
81
|
-
return html`
|
|
82
|
-
<sp-radio autofocus ${spreadProps(args)}>Radio</sp-radio>
|
|
83
|
-
`;
|
|
84
|
-
};
|
|
85
|
-
export const Invalid = (args) => renderRadio(args);
|
|
86
|
-
Invalid.args = {
|
|
87
|
-
invalid: true
|
|
88
|
-
};
|
|
89
|
-
export const Disabled = (args) => renderRadio(args);
|
|
90
|
-
Disabled.args = {
|
|
91
|
-
disabled: true
|
|
92
|
-
};
|
|
93
|
-
export const labelBelow = (args) => {
|
|
94
|
-
return html`
|
|
95
|
-
<sp-radio label-below ${spreadProps(args)}>Radio</sp-radio>
|
|
96
|
-
`;
|
|
97
|
-
};
|
|
98
|
-
labelBelow.storyName = "Label below";
|
|
99
|
-
const values = {
|
|
100
|
-
first: 1,
|
|
101
|
-
second: 2,
|
|
102
|
-
third: 3,
|
|
103
|
-
fourth: 4
|
|
104
|
-
};
|
|
105
|
-
export const groupExample = () => {
|
|
106
|
-
return html`
|
|
1
|
+
import{html as a}from"@spectrum-web-components/base";import"@spectrum-web-components/radio/sp-radio.js";import"@spectrum-web-components/radio/sp-radio-group.js";import{spreadProps as t}from"../../../test/lit-helpers.js";export default{component:"sp-radio",title:"Radio",argTypes:{checked:{name:"checked",type:{name:"boolean",required:!1},description:"Represents when the input is checked",table:{type:{summary:"boolean"},defaultValue:{summary:!1}},control:"boolean"},disabled:{name:"disabled",type:{name:"boolean",required:!1},description:"Disable this control. It will not receive focus or events.",table:{type:{summary:"boolean"},defaultValue:{summary:!1}},control:{type:"boolean"}},emphasized:{name:"emphasized",type:{name:"boolean",required:!1},description:"Set the button's state to emphasized.",table:{type:{summary:"boolean"},defaultValue:{summary:!1}},control:{type:"boolean"}},invalid:{name:"invalid",type:{name:"boolean",required:!1},table:{type:{summary:"boolean"},defaultValue:{summary:!1}},control:{type:"boolean"}}},args:{checked:!1,disabled:!1,emphasized:!1,invalid:!1}};function o(e){return a`
|
|
2
|
+
<sp-radio ${t(e)}>Radio</sp-radio>
|
|
3
|
+
`}export const Default=e=>o(e),readonly=e=>o({...e,readonly:!0});readonly.args={checked:!0};export const Emphasized=e=>o(e);Emphasized.args={checked:!0,emphasized:!0};export const Autofocus=e=>a`
|
|
4
|
+
<sp-radio autofocus ${t(e)}>Radio</sp-radio>
|
|
5
|
+
`,Invalid=e=>o(e);Invalid.args={invalid:!0};export const Disabled=e=>o(e);Disabled.args={disabled:!0};export const labelBelow=e=>a`
|
|
6
|
+
<sp-radio label-below ${t(e)}>Radio</sp-radio>
|
|
7
|
+
`;labelBelow.storyName="Label below";const r={first:1,second:2,third:3,fourth:4};export const groupExample=()=>a`
|
|
107
8
|
<sp-radio-group vertical selected="1" name="group-example">
|
|
108
|
-
<sp-radio value=${
|
|
109
|
-
<sp-radio value=${
|
|
110
|
-
<sp-radio value=${
|
|
111
|
-
<sp-radio value=${
|
|
9
|
+
<sp-radio value=${r.first}>Option 1</sp-radio>
|
|
10
|
+
<sp-radio value=${r.second}>Option 2</sp-radio>
|
|
11
|
+
<sp-radio value=${r.third}>Option 3</sp-radio>
|
|
12
|
+
<sp-radio value=${r.fourth}>Option 4</sp-radio>
|
|
112
13
|
</sp-radio-group>
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
export const horizontalGroup = () => {
|
|
116
|
-
return html`
|
|
14
|
+
`,horizontalGroup=()=>a`
|
|
117
15
|
<sp-radio-group horizontal selected="first" name="group-example">
|
|
118
16
|
<sp-radio value="first">Option 1</sp-radio>
|
|
119
17
|
<sp-radio value="second">Option 2</sp-radio>
|
|
120
18
|
<sp-radio value="third">Option 3</sp-radio>
|
|
121
19
|
<sp-radio value="fourth">Option 4</sp-radio>
|
|
122
20
|
</sp-radio-group>
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
export const horizontalLabelBelowGroup = () => {
|
|
126
|
-
return html`
|
|
21
|
+
`,horizontalLabelBelowGroup=()=>a`
|
|
127
22
|
<sp-radio-group horizontal selected="first" name="group-example">
|
|
128
23
|
<sp-radio value="first" label-below>Option 1</sp-radio>
|
|
129
24
|
<sp-radio value="second" label-below>Option 2</sp-radio>
|
|
130
25
|
<sp-radio value="third" label-below>Option 3</sp-radio>
|
|
131
26
|
<sp-radio value="fourth" label-below>Option 4</sp-radio>
|
|
132
27
|
</sp-radio-group>
|
|
133
|
-
|
|
134
|
-
};
|
|
135
|
-
export const tabIndexExample = () => {
|
|
136
|
-
return html`
|
|
28
|
+
`,tabIndexExample=()=>a`
|
|
137
29
|
<sp-radio-group vertical name="group-example">
|
|
138
30
|
<sp-radio emphasized value="zero" tabindex="0">
|
|
139
31
|
Tab Index 0
|
|
@@ -143,10 +35,7 @@ export const tabIndexExample = () => {
|
|
|
143
35
|
<sp-radio value="four" tabindex="4">Tab Index 4</sp-radio>
|
|
144
36
|
<sp-radio invalid value="two" tabindex="2">Tab Index 2</sp-radio>
|
|
145
37
|
</sp-radio-group>
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
export const horizontalTabIndexExample = () => {
|
|
149
|
-
return html`
|
|
38
|
+
`,horizontalTabIndexExample=()=>a`
|
|
150
39
|
<sp-radio-group horizontal name="group-example">
|
|
151
40
|
<sp-radio emphasized value="zero" tabindex="0">
|
|
152
41
|
Tab Index 0
|
|
@@ -156,7 +45,5 @@ export const horizontalTabIndexExample = () => {
|
|
|
156
45
|
<sp-radio value="four" tabindex="4">Tab Index 4</sp-radio>
|
|
157
46
|
<sp-radio invalid value="two" tabindex="2">Tab Index 2</sp-radio>
|
|
158
47
|
</sp-radio-group>
|
|
159
|
-
`;
|
|
160
|
-
};
|
|
161
|
-
tabIndexExample.storyName = "Tab index example";
|
|
48
|
+
`;tabIndexExample.storyName="Tab index example";
|
|
162
49
|
//# sourceMappingURL=radio.stories.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["radio.stories.ts"],
|
|
4
4
|
"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*/\nimport { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport '@spectrum-web-components/radio/sp-radio-group.js';\nimport { spreadProps } from '../../../test/lit-helpers.js';\n\nexport default {\n component: 'sp-radio',\n title: 'Radio',\n argTypes: {\n checked: {\n name: 'checked',\n type: { name: 'boolean', required: false },\n description: 'Represents when the input is checked',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: 'boolean',\n },\n disabled: {\n name: 'disabled',\n type: { name: 'boolean', required: false },\n description:\n 'Disable this control. It will not receive focus or events.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n emphasized: {\n name: 'emphasized',\n type: { name: 'boolean', required: false },\n description: \"Set the button's state to emphasized.\",\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n invalid: {\n name: 'invalid',\n type: { name: 'boolean', required: false },\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n },\n args: {\n checked: false,\n disabled: false,\n emphasized: false,\n invalid: false,\n },\n};\n\ninterface StoryArgs {\n checked?: boolean;\n disabled?: boolean;\n emphasized?: boolean;\n invalid?: boolean;\n readonly?: boolean;\n [prop: string]: unknown;\n}\n\nfunction renderRadio(args: StoryArgs): TemplateResult {\n return html`\n <sp-radio ${spreadProps(args)}>Radio</sp-radio>\n `;\n}\nexport const Default = (args: StoryArgs): TemplateResult => renderRadio(args);\n\nexport const readonly = (args: StoryArgs): TemplateResult =>\n renderRadio({\n ...args,\n readonly: true,\n });\nreadonly.args = {\n checked: true,\n};\n\nexport const Emphasized = (args: StoryArgs): TemplateResult =>\n renderRadio(args);\nEmphasized.args = {\n checked: true,\n emphasized: true,\n};\n\nexport const Autofocus = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-radio autofocus ${spreadProps(args)}>Radio</sp-radio>\n `;\n};\n\nexport const Invalid = (args: StoryArgs): TemplateResult => renderRadio(args);\nInvalid.args = {\n invalid: true,\n};\n\nexport const Disabled = (args: StoryArgs): TemplateResult => renderRadio(args);\nDisabled.args = {\n disabled: true,\n};\n\nexport const labelBelow = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-radio label-below ${spreadProps(args)}>Radio</sp-radio>\n `;\n};\nlabelBelow.storyName = 'Label below';\n\nconst values = {\n first: 1,\n second: 2,\n third: 3,\n fourth: 4,\n};\n\nexport const groupExample = (): TemplateResult => {\n return html`\n <sp-radio-group vertical selected=\"1\" name=\"group-example\">\n <sp-radio value=${values.first}>Option 1</sp-radio>\n <sp-radio value=${values.second}>Option 2</sp-radio>\n <sp-radio value=${values.third}>Option 3</sp-radio>\n <sp-radio value=${values.fourth}>Option 4</sp-radio>\n </sp-radio-group>\n `;\n};\n\nexport const horizontalGroup = (): TemplateResult => {\n return html`\n <sp-radio-group horizontal selected=\"first\" name=\"group-example\">\n <sp-radio value=\"first\">Option 1</sp-radio>\n <sp-radio value=\"second\">Option 2</sp-radio>\n <sp-radio value=\"third\">Option 3</sp-radio>\n <sp-radio value=\"fourth\">Option 4</sp-radio>\n </sp-radio-group>\n `;\n};\n\nexport const horizontalLabelBelowGroup = (): TemplateResult => {\n return html`\n <sp-radio-group horizontal selected=\"first\" name=\"group-example\">\n <sp-radio value=\"first\" label-below>Option 1</sp-radio>\n <sp-radio value=\"second\" label-below>Option 2</sp-radio>\n <sp-radio value=\"third\" label-below>Option 3</sp-radio>\n <sp-radio value=\"fourth\" label-below>Option 4</sp-radio>\n </sp-radio-group>\n `;\n};\n\nexport const tabIndexExample = (): TemplateResult => {\n return html`\n <sp-radio-group vertical name=\"group-example\">\n <sp-radio emphasized value=\"zero\" tabindex=\"0\">\n Tab Index 0\n </sp-radio>\n <sp-radio disabled value=\"three\" tabindex=\"3\">Tab Index 3</sp-radio>\n <sp-radio value=\"one\" tabindex=\"1\" autofocus>Tab Index 1</sp-radio>\n <sp-radio value=\"four\" tabindex=\"4\">Tab Index 4</sp-radio>\n <sp-radio invalid value=\"two\" tabindex=\"2\">Tab Index 2</sp-radio>\n </sp-radio-group>\n `;\n};\n\nexport const horizontalTabIndexExample = (): TemplateResult => {\n return html`\n <sp-radio-group horizontal name=\"group-example\">\n <sp-radio emphasized value=\"zero\" tabindex=\"0\">\n Tab Index 0\n </sp-radio>\n <sp-radio disabled value=\"three\" tabindex=\"3\">Tab Index 3</sp-radio>\n <sp-radio value=\"one\" tabindex=\"1\" autofocus>Tab Index 1</sp-radio>\n <sp-radio value=\"four\" tabindex=\"4\">Tab Index 4</sp-radio>\n <sp-radio invalid value=\"two\" tabindex=\"2\">Tab Index 2</sp-radio>\n </sp-radio-group>\n `;\n};\n\ntabIndexExample.storyName = 'Tab index example';\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,qDAEA,mDACA,yDACA,2DAEA,cAAe,CACX,UAAW,WACX,MAAO,QACP,SAAU,CACN,QAAS,CACL,KAAM,UACN,KAAM,CAAE,KAAM,UAAW,SAAU,EAAM,EACzC,YAAa,uCACb,MAAO,CACH,KAAM,CAAE,QAAS,SAAU,EAC3B,aAAc,CAAE,QAAS,EAAM,CACnC,EACA,QAAS,SACb,EACA,SAAU,CACN,KAAM,WACN,KAAM,CAAE,KAAM,UAAW,SAAU,EAAM,EACzC,YACI,6DACJ,MAAO,CACH,KAAM,CAAE,QAAS,SAAU,EAC3B,aAAc,CAAE,QAAS,EAAM,CACnC,EACA,QAAS,CACL,KAAM,SACV,CACJ,EACA,WAAY,CACR,KAAM,aACN,KAAM,CAAE,KAAM,UAAW,SAAU,EAAM,EACzC,YAAa,wCACb,MAAO,CACH,KAAM,CAAE,QAAS,SAAU,EAC3B,aAAc,CAAE,QAAS,EAAM,CACnC,EACA,QAAS,CACL,KAAM,SACV,CACJ,EACA,QAAS,CACL,KAAM,UACN,KAAM,CAAE,KAAM,UAAW,SAAU,EAAM,EACzC,MAAO,CACH,KAAM,CAAE,QAAS,SAAU,EAC3B,aAAc,CAAE,QAAS,EAAM,CACnC,EACA,QAAS,CACL,KAAM,SACV,CACJ,CACJ,EACA,KAAM,CACF,QAAS,GACT,SAAU,GACV,WAAY,GACZ,QAAS,EACb,CACJ,EAWA,WAAqB,EAAiC,CAClD,MAAO;AAAA,oBACS,EAAY,CAAI;AAAA,KAEpC,CACO,YAAM,SAAU,AAAC,GAAoC,EAAY,CAAI,EAE/D,SAAW,AAAC,GACrB,EAAY,IACL,EACH,SAAU,EACd,CAAC,EACL,SAAS,KAAO,CACZ,QAAS,EACb,EAEO,YAAM,YAAa,AAAC,GACvB,EAAY,CAAI,EACpB,WAAW,KAAO,CACd,QAAS,GACT,WAAY,EAChB,EAEO,YAAM,WAAY,AAAC,GACf;AAAA,8BACmB,EAAY,CAAI;AAAA,MAIjC,QAAU,AAAC,GAAoC,EAAY,CAAI,EAC5E,QAAQ,KAAO,CACX,QAAS,EACb,EAEO,YAAM,UAAW,AAAC,GAAoC,EAAY,CAAI,EAC7E,SAAS,KAAO,CACZ,SAAU,EACd,EAEO,YAAM,YAAa,AAAC,GAChB;AAAA,gCACqB,EAAY,CAAI;AAAA,MAGhD,WAAW,UAAY,cAEvB,KAAM,GAAS,CACX,MAAO,EACP,OAAQ,EACR,MAAO,EACP,OAAQ,CACZ,EAEO,YAAM,cAAe,IACjB;AAAA;AAAA,8BAEmB,EAAO;AAAA,8BACP,EAAO;AAAA,8BACP,EAAO;AAAA,8BACP,EAAO;AAAA;AAAA,MAKxB,gBAAkB,IACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAUE,0BAA4B,IAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAUE,gBAAkB,IACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAaE,0BAA4B,IAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAaX,gBAAgB,UAAY",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "@spectrum-web-components/radio/sp-radio.js";
|
|
3
|
-
import { html } from "lit";
|
|
4
|
-
import { measureFixtureCreation } from "../../../../test/benchmark/helpers.js";
|
|
5
|
-
measureFixtureCreation(html`
|
|
1
|
+
import"@spectrum-web-components/radio/sp-radio-group.js";import"@spectrum-web-components/radio/sp-radio.js";import{html as o}from"lit";import{measureFixtureCreation as r}from"../../../../test/benchmark/helpers.js";r(o`
|
|
6
2
|
<sp-radio-group id="test-default">
|
|
7
3
|
<sp-radio value="first" checked>Option 1</sp-radio>
|
|
8
4
|
<sp-radio value="second">Option 2</sp-radio>
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["test-basic.ts"],
|
|
4
4
|
"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 '@spectrum-web-components/radio/sp-radio-group.js';\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-radio-group id=\"test-default\">\n <sp-radio value=\"first\" checked>Option 1</sp-radio>\n <sp-radio value=\"second\">Option 2</sp-radio>\n <sp-radio value=\"third\">Option 3</sp-radio>\n </sp-radio-group>\n`);\n"],
|
|
5
|
-
"mappings": "AAYA
|
|
5
|
+
"mappings": "AAYA,yDACA,mDACA,2BACA,+EAEA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAMtB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/test/radio-group.test.js
CHANGED
|
@@ -1,80 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "@spectrum-web-components/radio/sp-radio.js";
|
|
3
|
-
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
4
|
-
import {
|
|
5
|
-
arrowDownEvent,
|
|
6
|
-
arrowLeftEvent,
|
|
7
|
-
arrowRightEvent,
|
|
8
|
-
arrowUpEvent,
|
|
9
|
-
endEvent,
|
|
10
|
-
enterEvent,
|
|
11
|
-
homeEvent
|
|
12
|
-
} from "../../../test/testing-helpers.js";
|
|
13
|
-
import {
|
|
14
|
-
a11ySnapshot,
|
|
15
|
-
findAccessibilityNode,
|
|
16
|
-
sendKeys
|
|
17
|
-
} from "@web/test-runner-commands";
|
|
18
|
-
import { sendMouse } from "../../../test/plugins/browser.js";
|
|
19
|
-
import { spy } from "sinon";
|
|
20
|
-
describe("Radio Group - focus control", () => {
|
|
21
|
-
it("does not accept focus when empty", async () => {
|
|
22
|
-
const el = await fixture(html`
|
|
1
|
+
import"@spectrum-web-components/radio/sp-radio-group.js";import"@spectrum-web-components/radio/sp-radio.js";import{elementUpdated as i,expect as o,fixture as r,html as c}from"@open-wc/testing";import{arrowDownEvent as n,arrowLeftEvent as f,arrowRightEvent as k,arrowUpEvent as u,endEvent as h,enterEvent as m,homeEvent as v}from"../../../test/testing-helpers.js";import{a11ySnapshot as g,findAccessibilityNode as l,sendKeys as y}from"@web/test-runner-commands";import{sendMouse as q}from"../../../test/plugins/browser.js";import{spy as R}from"sinon";describe("Radio Group - focus control",()=>{it("does not accept focus when empty",async()=>{const t=await r(c`
|
|
23
2
|
<sp-radio-group></sp-radio-group>
|
|
24
|
-
`);
|
|
25
|
-
await elementUpdated(el);
|
|
26
|
-
expect(document.activeElement === el).to.be.false;
|
|
27
|
-
el.focus();
|
|
28
|
-
await elementUpdated(el);
|
|
29
|
-
expect(document.activeElement === el).to.be.false;
|
|
30
|
-
});
|
|
31
|
-
it("focuses selected before first", async () => {
|
|
32
|
-
const values = ["first", "second", "third"];
|
|
33
|
-
const el = await fixture(html`
|
|
3
|
+
`);await i(t),o(document.activeElement===t).to.be.false,t.focus(),await i(t),o(document.activeElement===t).to.be.false}),it("focuses selected before first",async()=>{const t=["first","second","third"],e=await r(c`
|
|
34
4
|
<sp-radio-group selected="second">
|
|
35
|
-
<sp-radio value=${
|
|
36
|
-
<sp-radio value=${
|
|
37
|
-
<sp-radio value=${
|
|
5
|
+
<sp-radio value=${t[0]}>Option 1</sp-radio>
|
|
6
|
+
<sp-radio value=${t[1]}>Option 2</sp-radio>
|
|
7
|
+
<sp-radio value=${t[2]}>Option 3</sp-radio>
|
|
38
8
|
</sp-radio-group>
|
|
39
|
-
`);
|
|
40
|
-
await elementUpdated(el);
|
|
41
|
-
const selected = el.querySelector('[value="second"]');
|
|
42
|
-
expect(document.activeElement === el).to.be.false;
|
|
43
|
-
el.focus();
|
|
44
|
-
await elementUpdated(el);
|
|
45
|
-
expect(document.activeElement === selected).to.be.true;
|
|
46
|
-
});
|
|
47
|
-
it("focuses the child input not the root when [tabindex=-1]", async () => {
|
|
48
|
-
const values = ["first", "second", "third"];
|
|
49
|
-
const el = await fixture(html`
|
|
9
|
+
`);await i(e);const a=e.querySelector('[value="second"]');o(document.activeElement===e).to.be.false,e.focus(),await i(e),o(document.activeElement===a).to.be.true}),it("focuses the child input not the root when [tabindex=-1]",async()=>{const t=["first","second","third"],e=await r(c`
|
|
50
10
|
<sp-radio-group selected="second">
|
|
51
|
-
<sp-radio value=${
|
|
52
|
-
<sp-radio value=${
|
|
53
|
-
<sp-radio value=${
|
|
11
|
+
<sp-radio value=${t[0]}>Option 1</sp-radio>
|
|
12
|
+
<sp-radio value=${t[1]}>Option 2</sp-radio>
|
|
13
|
+
<sp-radio value=${t[2]}>Option 3</sp-radio>
|
|
54
14
|
</sp-radio-group>
|
|
55
|
-
`);
|
|
56
|
-
await elementUpdated(el);
|
|
57
|
-
const first = el.querySelector('[value="first"]');
|
|
58
|
-
const selected = el.querySelector('[value="second"]');
|
|
59
|
-
expect(selected.tabIndex).to.equal(0);
|
|
60
|
-
expect(first.tabIndex).to.equal(-1);
|
|
61
|
-
const firstRect = first.getBoundingClientRect();
|
|
62
|
-
await sendMouse({
|
|
63
|
-
steps: [
|
|
64
|
-
{
|
|
65
|
-
type: "move",
|
|
66
|
-
position: [firstRect.x + 2, firstRect.y + 2]
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
type: "down"
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
});
|
|
73
|
-
await elementUpdated(el);
|
|
74
|
-
expect(!first.matches(":focus") || first.matches(":focus-within"), "root should not").to.be.true;
|
|
75
|
-
});
|
|
76
|
-
it("does not select on focus", async () => {
|
|
77
|
-
const el = await fixture(html`
|
|
15
|
+
`);await i(e);const a=e.querySelector('[value="first"]'),d=e.querySelector('[value="second"]');o(d.tabIndex).to.equal(0),o(a.tabIndex).to.equal(-1);const s=a.getBoundingClientRect();await q({steps:[{type:"move",position:[s.x+2,s.y+2]},{type:"down"}]}),await i(e),o(!a.matches(":focus")||a.matches(":focus-within"),"root should not").to.be.true}),it("does not select on focus",async()=>{const t=await r(c`
|
|
78
16
|
<sp-radio-group>
|
|
79
17
|
<sp-radio value="1">Options 1</sp-radio>
|
|
80
18
|
<sp-radio value="2">Options 2</sp-radio>
|
|
@@ -82,25 +20,7 @@ describe("Radio Group - focus control", () => {
|
|
|
82
20
|
<sp-radio value="4">Options 4</sp-radio>
|
|
83
21
|
<sp-radio value="5">Options 5</sp-radio>
|
|
84
22
|
</sp-radio-group>
|
|
85
|
-
`);
|
|
86
|
-
await elementUpdated(el);
|
|
87
|
-
const radio1 = el.querySelector("sp-radio:nth-child(1)");
|
|
88
|
-
const radio2 = el.querySelector("sp-radio:nth-child(2)");
|
|
89
|
-
expect(el.selected).to.equal("");
|
|
90
|
-
radio1.focus();
|
|
91
|
-
await elementUpdated(el);
|
|
92
|
-
expect(el.selected).to.equal("");
|
|
93
|
-
el.selected = "1";
|
|
94
|
-
await elementUpdated(el);
|
|
95
|
-
expect(el.selected).to.equal("1");
|
|
96
|
-
expect(radio1.checked).to.be.true;
|
|
97
|
-
radio2.focus();
|
|
98
|
-
await elementUpdated(el);
|
|
99
|
-
expect(el.selected).to.equal("1");
|
|
100
|
-
expect(radio1.checked).to.be.true;
|
|
101
|
-
});
|
|
102
|
-
it("loads accepts keyboard events while focused", async () => {
|
|
103
|
-
const el = await fixture(html`
|
|
23
|
+
`);await i(t);const e=t.querySelector("sp-radio:nth-child(1)"),a=t.querySelector("sp-radio:nth-child(2)");o(t.selected).to.equal(""),e.focus(),await i(t),o(t.selected).to.equal(""),t.selected="1",await i(t),o(t.selected).to.equal("1"),o(e.checked).to.be.true,a.focus(),await i(t),o(t.selected).to.equal("1"),o(e.checked).to.be.true}),it("loads accepts keyboard events while focused",async()=>{const t=await r(c`
|
|
104
24
|
<sp-radio-group>
|
|
105
25
|
<sp-radio>Options 1</sp-radio>
|
|
106
26
|
<sp-radio>Options 2</sp-radio>
|
|
@@ -108,37 +28,7 @@ describe("Radio Group - focus control", () => {
|
|
|
108
28
|
<sp-radio>Options 4</sp-radio>
|
|
109
29
|
<sp-radio>Options 5</sp-radio>
|
|
110
30
|
</sp-radio-group>
|
|
111
|
-
`);
|
|
112
|
-
await elementUpdated(el);
|
|
113
|
-
const radio1 = el.querySelector("sp-radio:nth-child(1)");
|
|
114
|
-
const radio2 = el.querySelector("sp-radio:nth-child(2)");
|
|
115
|
-
const radio3 = el.querySelector("sp-radio:nth-child(3)");
|
|
116
|
-
const radio4 = el.querySelector("sp-radio:nth-child(4)");
|
|
117
|
-
const radio5 = el.querySelector("sp-radio:nth-child(5)");
|
|
118
|
-
radio1.focus();
|
|
119
|
-
await elementUpdated(el);
|
|
120
|
-
el.dispatchEvent(arrowRightEvent());
|
|
121
|
-
await elementUpdated(el);
|
|
122
|
-
expect(document.activeElement === radio2).to.be.true;
|
|
123
|
-
el.dispatchEvent(arrowDownEvent());
|
|
124
|
-
await elementUpdated(el);
|
|
125
|
-
expect(document.activeElement === radio3).to.be.true;
|
|
126
|
-
el.dispatchEvent(endEvent());
|
|
127
|
-
await elementUpdated(el);
|
|
128
|
-
expect(document.activeElement === radio5).to.be.true;
|
|
129
|
-
el.dispatchEvent(arrowLeftEvent());
|
|
130
|
-
await elementUpdated(el);
|
|
131
|
-
expect(document.activeElement === radio4).to.be.true;
|
|
132
|
-
el.dispatchEvent(arrowUpEvent());
|
|
133
|
-
await elementUpdated(el);
|
|
134
|
-
expect(document.activeElement === radio3).to.be.true;
|
|
135
|
-
el.dispatchEvent(homeEvent());
|
|
136
|
-
await elementUpdated(el);
|
|
137
|
-
expect(document.activeElement === radio1).to.be.true;
|
|
138
|
-
radio1.blur();
|
|
139
|
-
});
|
|
140
|
-
it("accepts keyboard interactions where `checked` and `calculateFocusInIndex` might conflict", async () => {
|
|
141
|
-
const el = await fixture(html`
|
|
31
|
+
`);await i(t);const e=t.querySelector("sp-radio:nth-child(1)"),a=t.querySelector("sp-radio:nth-child(2)"),d=t.querySelector("sp-radio:nth-child(3)"),s=t.querySelector("sp-radio:nth-child(4)"),p=t.querySelector("sp-radio:nth-child(5)");e.focus(),await i(t),t.dispatchEvent(k()),await i(t),o(document.activeElement===a).to.be.true,t.dispatchEvent(n()),await i(t),o(document.activeElement===d).to.be.true,t.dispatchEvent(h()),await i(t),o(document.activeElement===p).to.be.true,t.dispatchEvent(f()),await i(t),o(document.activeElement===s).to.be.true,t.dispatchEvent(u()),await i(t),o(document.activeElement===d).to.be.true,t.dispatchEvent(v()),await i(t),o(document.activeElement===e).to.be.true,e.blur()}),it("accepts keyboard interactions where `checked` and `calculateFocusInIndex` might conflict",async()=>{const t=await r(c`
|
|
142
32
|
<sp-radio-group>
|
|
143
33
|
<sp-radio>Options 1</sp-radio>
|
|
144
34
|
<sp-radio>Options 2</sp-radio>
|
|
@@ -146,23 +36,7 @@ describe("Radio Group - focus control", () => {
|
|
|
146
36
|
<sp-radio>Options 4</sp-radio>
|
|
147
37
|
<sp-radio>Options 5</sp-radio>
|
|
148
38
|
</sp-radio-group>
|
|
149
|
-
`);
|
|
150
|
-
await elementUpdated(el);
|
|
151
|
-
const radio1 = el.querySelector("sp-radio:nth-child(1)");
|
|
152
|
-
const radio5 = el.querySelector("sp-radio:nth-child(5)");
|
|
153
|
-
radio5.focus();
|
|
154
|
-
await elementUpdated(el);
|
|
155
|
-
expect(document.activeElement === radio5).to.be.true;
|
|
156
|
-
expect(radio5.checked).to.be.true;
|
|
157
|
-
await sendKeys({
|
|
158
|
-
press: "ArrowRight"
|
|
159
|
-
});
|
|
160
|
-
await elementUpdated(el);
|
|
161
|
-
expect(document.activeElement === radio1).to.be.true;
|
|
162
|
-
expect(radio1.checked).to.be.true;
|
|
163
|
-
});
|
|
164
|
-
it("acknowledges `disabled` and accepts keyboard events while focused", async () => {
|
|
165
|
-
const el = await fixture(html`
|
|
39
|
+
`);await i(t);const e=t.querySelector("sp-radio:nth-child(1)"),a=t.querySelector("sp-radio:nth-child(5)");a.focus(),await i(t),o(document.activeElement===a).to.be.true,o(a.checked).to.be.true,await y({press:"ArrowRight"}),await i(t),o(document.activeElement===e).to.be.true,o(e.checked).to.be.true}),it("acknowledges `disabled` and accepts keyboard events while focused",async()=>{const t=await r(c`
|
|
166
40
|
<sp-radio-group>
|
|
167
41
|
<sp-radio value="1" disabled>Option 1</sp-radio>
|
|
168
42
|
<sp-radio value="2">Option 2</sp-radio>
|
|
@@ -170,49 +44,13 @@ describe("Radio Group - focus control", () => {
|
|
|
170
44
|
<sp-radio value="4">Option 4</sp-radio>
|
|
171
45
|
<sp-radio value="5" disabled>Option 5</sp-radio>
|
|
172
46
|
</sp-radio-group>
|
|
173
|
-
`);
|
|
174
|
-
await elementUpdated(el);
|
|
175
|
-
const radio2 = el.querySelector("sp-radio:nth-child(2)");
|
|
176
|
-
const radio4 = el.querySelector("sp-radio:nth-child(4)");
|
|
177
|
-
radio2.focus();
|
|
178
|
-
await elementUpdated(el);
|
|
179
|
-
expect(document.activeElement === radio2, "start 2").to.be.true;
|
|
180
|
-
expect(el.selected).to.equal("");
|
|
181
|
-
el.dispatchEvent(enterEvent());
|
|
182
|
-
el.dispatchEvent(endEvent());
|
|
183
|
-
await elementUpdated(el);
|
|
184
|
-
expect(document.activeElement === radio4, "first 4").to.be.true;
|
|
185
|
-
expect(el.selected).to.equal("4");
|
|
186
|
-
el.dispatchEvent(homeEvent());
|
|
187
|
-
await elementUpdated(el);
|
|
188
|
-
expect(document.activeElement === radio2, "second 2").to.be.true;
|
|
189
|
-
el.dispatchEvent(arrowUpEvent());
|
|
190
|
-
await elementUpdated(el);
|
|
191
|
-
expect(document.activeElement === radio4, "third 4").to.be.true;
|
|
192
|
-
el.dispatchEvent(arrowDownEvent());
|
|
193
|
-
await elementUpdated(el);
|
|
194
|
-
expect(document.activeElement === radio2, "fourth 2").to.be.true;
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
describe("Group Accessibility", () => {
|
|
198
|
-
it("created the expected accessibility tree", async () => {
|
|
199
|
-
await fixture(html`
|
|
47
|
+
`);await i(t);const e=t.querySelector("sp-radio:nth-child(2)"),a=t.querySelector("sp-radio:nth-child(4)");e.focus(),await i(t),o(document.activeElement===e,"start 2").to.be.true,o(t.selected).to.equal(""),t.dispatchEvent(m()),t.dispatchEvent(h()),await i(t),o(document.activeElement===a,"first 4").to.be.true,o(t.selected).to.equal("4"),t.dispatchEvent(v()),await i(t),o(document.activeElement===e,"second 2").to.be.true,t.dispatchEvent(u()),await i(t),o(document.activeElement===a,"third 4").to.be.true,t.dispatchEvent(n()),await i(t),o(document.activeElement===e,"fourth 2").to.be.true})}),describe("Group Accessibility",()=>{it("created the expected accessibility tree",async()=>{await r(c`
|
|
200
48
|
<sp-radio-group label="Testing Label" tabindex="0">
|
|
201
49
|
<sp-radio value="first">Option 1</sp-radio>
|
|
202
50
|
<sp-radio value="second" checked>Option 2</sp-radio>
|
|
203
51
|
<sp-radio value="third">Option 3</sp-radio>
|
|
204
52
|
</sp-radio-group>
|
|
205
|
-
`);
|
|
206
|
-
const snapshot = await a11ySnapshot({});
|
|
207
|
-
expect(findAccessibilityNode(snapshot, (node) => (node.role === "radiogroup" || node.role === "group") && node.name === "Testing Label"), 'Has a "radiogroup" with the supplied name').to.not.be.null;
|
|
208
|
-
expect(findAccessibilityNode(snapshot, (node) => node.role === "radio" && node.checked && node.name === "Option 2"), 'Has a named and checked "radio" element').to.not.be.null;
|
|
209
|
-
expect(findAccessibilityNode(snapshot, (node) => node.name === "Option 2" && node.role.startsWith("text")), 'Does not have a text leaf named like the "radio" element').to.be.null;
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
describe("Radio Group", () => {
|
|
213
|
-
let testDiv;
|
|
214
|
-
beforeEach(async () => {
|
|
215
|
-
testDiv = await fixture(html`
|
|
53
|
+
`);const t=await g({});o(l(t,e=>(e.role==="radiogroup"||e.role==="group")&&e.name==="Testing Label"),'Has a "radiogroup" with the supplied name').to.not.be.null,o(l(t,e=>e.role==="radio"&&e.checked&&e.name==="Option 2"),'Has a named and checked "radio" element').to.not.be.null,o(l(t,e=>e.name==="Option 2"&&e.role.startsWith("text")),'Does not have a text leaf named like the "radio" element').to.be.null})}),describe("Radio Group",()=>{let t;beforeEach(async()=>{t=await r(c`
|
|
216
54
|
<div id="test-radio-group">
|
|
217
55
|
<sp-radio-group id="test-default">
|
|
218
56
|
<sp-radio value="first" checked>Option 1</sp-radio>
|
|
@@ -259,155 +97,11 @@ describe("Radio Group", () => {
|
|
|
259
97
|
<sp-radio value="third">Option 3</sp-radio>
|
|
260
98
|
</sp-radio-group>
|
|
261
99
|
</div>
|
|
262
|
-
`);
|
|
263
|
-
|
|
264
|
-
it("loads", () => {
|
|
265
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-default");
|
|
266
|
-
const radioChildren = radioGroup.querySelectorAll("sp-radio");
|
|
267
|
-
expect(radioGroup).to.exist;
|
|
268
|
-
expect(radioChildren.length).to.equal(3);
|
|
269
|
-
});
|
|
270
|
-
it("loads accessibly", async () => {
|
|
271
|
-
await expect(testDiv).to.be.accessible();
|
|
272
|
-
});
|
|
273
|
-
it("validates selection", async () => {
|
|
274
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-none-selected");
|
|
275
|
-
expect(radioGroup.selected).to.equal("");
|
|
276
|
-
radioGroup.selected = "missing";
|
|
277
|
-
await elementUpdated(radioGroup);
|
|
278
|
-
expect(radioGroup.selected).to.equal("");
|
|
279
|
-
});
|
|
280
|
-
it("can have selection prevented", async () => {
|
|
281
|
-
const el = testDiv.querySelector("sp-radio-group#test-default");
|
|
282
|
-
const secondRadio = el.querySelector("sp-radio[value=second]");
|
|
283
|
-
const thirdRadio = el.querySelector("sp-radio[value=third]");
|
|
284
|
-
await elementUpdated(el);
|
|
285
|
-
expect(el.selected).to.equal("first");
|
|
286
|
-
secondRadio.click();
|
|
287
|
-
await elementUpdated(el);
|
|
288
|
-
expect(el.selected).to.equal("second");
|
|
289
|
-
el.addEventListener("change", (event) => event.preventDefault());
|
|
290
|
-
thirdRadio.click();
|
|
291
|
-
await elementUpdated(el);
|
|
292
|
-
expect(el.selected).to.equal("second");
|
|
293
|
-
});
|
|
294
|
-
it("reflects checked radio with selected property", async () => {
|
|
295
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-default");
|
|
296
|
-
const firstRadio = radioGroup.querySelector("sp-radio[value=first]");
|
|
297
|
-
const secondRadio = radioGroup.querySelector("sp-radio[value=second]");
|
|
298
|
-
const thirdRadio = radioGroup.querySelector("sp-radio[value=third]");
|
|
299
|
-
expect(firstRadio.checked).to.be.true;
|
|
300
|
-
expect(secondRadio.checked).to.be.false;
|
|
301
|
-
expect(thirdRadio.checked).to.be.false;
|
|
302
|
-
expect(radioGroup.selected).to.equal(firstRadio.value);
|
|
303
|
-
secondRadio.click();
|
|
304
|
-
await elementUpdated(radioGroup);
|
|
305
|
-
expect(firstRadio.checked).to.be.false;
|
|
306
|
-
expect(secondRadio.checked).to.be.true;
|
|
307
|
-
expect(thirdRadio.checked).to.be.false;
|
|
308
|
-
expect(radioGroup.selected).to.equal(secondRadio.value);
|
|
309
|
-
thirdRadio.click();
|
|
310
|
-
await elementUpdated(radioGroup);
|
|
311
|
-
expect(firstRadio.checked).to.be.false;
|
|
312
|
-
expect(secondRadio.checked).to.be.false;
|
|
313
|
-
expect(thirdRadio.checked).to.be.true;
|
|
314
|
-
expect(radioGroup.selected).to.equal(thirdRadio.value);
|
|
315
|
-
});
|
|
316
|
-
it("forces only one radio to be checked", () => {
|
|
317
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-multiple-checked");
|
|
318
|
-
const checkedRadios = radioGroup.querySelectorAll("sp-radio[checked]");
|
|
319
|
-
expect(radioGroup.selected).to.equal("first");
|
|
320
|
-
expect(checkedRadios.length).to.equal(1);
|
|
321
|
-
});
|
|
322
|
-
it("respects clicking on disabled attribute causing nothing to happen", async () => {
|
|
323
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-disabled");
|
|
324
|
-
const checkedRadio = radioGroup.querySelector("sp-radio[checked]");
|
|
325
|
-
const disabledRadio = radioGroup.querySelector("sp-radio[disabled]");
|
|
326
|
-
disabledRadio.click();
|
|
327
|
-
await elementUpdated(radioGroup);
|
|
328
|
-
expect(disabledRadio.checked).to.be.false;
|
|
329
|
-
expect(checkedRadio.checked).to.be.true;
|
|
330
|
-
expect(radioGroup.selected).to.equal(checkedRadio.value);
|
|
331
|
-
});
|
|
332
|
-
it("de-checks all but first checked radio if multiple checked", () => {
|
|
333
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-multiple-checked");
|
|
334
|
-
const radio1 = radioGroup.querySelector("sp-radio[value=first]");
|
|
335
|
-
const radio2 = radioGroup.querySelector("sp-radio[value=second]");
|
|
336
|
-
expect(radioGroup.selected).to.equal("first");
|
|
337
|
-
expect(radio1.checked).to.be.true;
|
|
338
|
-
expect(radio2.checked).to.be.false;
|
|
339
|
-
});
|
|
340
|
-
it("ensures setting selection updates checked radio", async () => {
|
|
341
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-selected");
|
|
342
|
-
const radio1 = radioGroup.querySelector("sp-radio[value=first]");
|
|
343
|
-
const radio2 = radioGroup.querySelector("sp-radio[value=second]");
|
|
344
|
-
const radio3 = radioGroup.querySelector("sp-radio[value=third]");
|
|
345
|
-
expect(radioGroup.selected).to.equal("third");
|
|
346
|
-
expect(radio1.checked).to.be.false;
|
|
347
|
-
expect(radio2.checked).to.be.false;
|
|
348
|
-
expect(radio3.checked, "initial").to.be.true;
|
|
349
|
-
radioGroup.selected = "second";
|
|
350
|
-
await elementUpdated(radioGroup);
|
|
351
|
-
expect(radioGroup.selected).to.equal("second");
|
|
352
|
-
expect(radio1.checked).to.be.false;
|
|
353
|
-
expect(radio2.checked, "second").to.be.true;
|
|
354
|
-
expect(radio3.checked).to.be.false;
|
|
355
|
-
radioGroup.selected = "first";
|
|
356
|
-
await elementUpdated(radioGroup);
|
|
357
|
-
expect(radioGroup.selected).to.equal("first");
|
|
358
|
-
expect(radio1.checked, "third").to.be.true;
|
|
359
|
-
expect(radio2.checked).to.be.false;
|
|
360
|
-
expect(radio3.checked).to.be.false;
|
|
361
|
-
});
|
|
362
|
-
it("ensures setting selected and clicking on radio both work together", async () => {
|
|
363
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-selected-click");
|
|
364
|
-
const radio1 = radioGroup.querySelector("sp-radio[value=first]");
|
|
365
|
-
const radio2 = radioGroup.querySelector("sp-radio[value=second]");
|
|
366
|
-
const radio3 = radioGroup.querySelector("sp-radio[value=third]");
|
|
367
|
-
expect(radioGroup.selected).to.equal("third");
|
|
368
|
-
radio2.click();
|
|
369
|
-
await elementUpdated(radioGroup);
|
|
370
|
-
expect(radioGroup.selected).to.equal("second");
|
|
371
|
-
expect(radio1.checked).to.be.false;
|
|
372
|
-
expect(radio2.checked).to.be.true;
|
|
373
|
-
expect(radio3.checked).to.be.false;
|
|
374
|
-
radioGroup.selected = "first";
|
|
375
|
-
await elementUpdated(radioGroup);
|
|
376
|
-
expect(radioGroup.selected).to.equal("first");
|
|
377
|
-
expect(radio1.checked, "moved to checked").to.be.true;
|
|
378
|
-
expect(radio2.checked).to.be.false;
|
|
379
|
-
expect(radio3.checked).to.be.false;
|
|
380
|
-
});
|
|
381
|
-
it("prioritizes checked over selected on initialization when conflicting", () => {
|
|
382
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-checked-prioritized");
|
|
383
|
-
const radio1 = radioGroup.querySelector("sp-radio[value=first]");
|
|
384
|
-
const radio2 = radioGroup.querySelector("sp-radio[value=second]");
|
|
385
|
-
expect(radioGroup.selected).to.equal("first");
|
|
386
|
-
expect(radio1.checked).to.be.true;
|
|
387
|
-
expect(radio2.checked).to.be.false;
|
|
388
|
-
});
|
|
389
|
-
it("handles integer values for radio buttons", () => {
|
|
390
|
-
const radioGroup = testDiv.querySelector("sp-radio-group#test-integer-value");
|
|
391
|
-
expect(radioGroup.selected).to.equal("5");
|
|
392
|
-
});
|
|
393
|
-
it("prevents `change` events from radio buttons", async () => {
|
|
394
|
-
const changeSpy = spy();
|
|
395
|
-
const onChange = (event) => {
|
|
396
|
-
changeSpy(event.target.selected);
|
|
397
|
-
};
|
|
398
|
-
const el = await fixture(html`
|
|
399
|
-
<sp-radio-group @change=${onChange}>
|
|
100
|
+
`)}),it("loads",()=>{const e=t.querySelector("sp-radio-group#test-default"),a=e.querySelectorAll("sp-radio");o(e).to.exist,o(a.length).to.equal(3)}),it("loads accessibly",async()=>{await o(t).to.be.accessible()}),it("validates selection",async()=>{const e=t.querySelector("sp-radio-group#test-none-selected");o(e.selected).to.equal(""),e.selected="missing",await i(e),o(e.selected).to.equal("")}),it("can have selection prevented",async()=>{const e=t.querySelector("sp-radio-group#test-default"),a=e.querySelector("sp-radio[value=second]"),d=e.querySelector("sp-radio[value=third]");await i(e),o(e.selected).to.equal("first"),a.click(),await i(e),o(e.selected).to.equal("second"),e.addEventListener("change",s=>s.preventDefault()),d.click(),await i(e),o(e.selected).to.equal("second")}),it("reflects checked radio with selected property",async()=>{const e=t.querySelector("sp-radio-group#test-default"),a=e.querySelector("sp-radio[value=first]"),d=e.querySelector("sp-radio[value=second]"),s=e.querySelector("sp-radio[value=third]");o(a.checked).to.be.true,o(d.checked).to.be.false,o(s.checked).to.be.false,o(e.selected).to.equal(a.value),d.click(),await i(e),o(a.checked).to.be.false,o(d.checked).to.be.true,o(s.checked).to.be.false,o(e.selected).to.equal(d.value),s.click(),await i(e),o(a.checked).to.be.false,o(d.checked).to.be.false,o(s.checked).to.be.true,o(e.selected).to.equal(s.value)}),it("forces only one radio to be checked",()=>{const e=t.querySelector("sp-radio-group#test-multiple-checked"),a=e.querySelectorAll("sp-radio[checked]");o(e.selected).to.equal("first"),o(a.length).to.equal(1)}),it("respects clicking on disabled attribute causing nothing to happen",async()=>{const e=t.querySelector("sp-radio-group#test-disabled"),a=e.querySelector("sp-radio[checked]"),d=e.querySelector("sp-radio[disabled]");d.click(),await i(e),o(d.checked).to.be.false,o(a.checked).to.be.true,o(e.selected).to.equal(a.value)}),it("de-checks all but first checked radio if multiple checked",()=>{const e=t.querySelector("sp-radio-group#test-multiple-checked"),a=e.querySelector("sp-radio[value=first]"),d=e.querySelector("sp-radio[value=second]");o(e.selected).to.equal("first"),o(a.checked).to.be.true,o(d.checked).to.be.false}),it("ensures setting selection updates checked radio",async()=>{const e=t.querySelector("sp-radio-group#test-selected"),a=e.querySelector("sp-radio[value=first]"),d=e.querySelector("sp-radio[value=second]"),s=e.querySelector("sp-radio[value=third]");o(e.selected).to.equal("third"),o(a.checked).to.be.false,o(d.checked).to.be.false,o(s.checked,"initial").to.be.true,e.selected="second",await i(e),o(e.selected).to.equal("second"),o(a.checked).to.be.false,o(d.checked,"second").to.be.true,o(s.checked).to.be.false,e.selected="first",await i(e),o(e.selected).to.equal("first"),o(a.checked,"third").to.be.true,o(d.checked).to.be.false,o(s.checked).to.be.false}),it("ensures setting selected and clicking on radio both work together",async()=>{const e=t.querySelector("sp-radio-group#test-selected-click"),a=e.querySelector("sp-radio[value=first]"),d=e.querySelector("sp-radio[value=second]"),s=e.querySelector("sp-radio[value=third]");o(e.selected).to.equal("third"),d.click(),await i(e),o(e.selected).to.equal("second"),o(a.checked).to.be.false,o(d.checked).to.be.true,o(s.checked).to.be.false,e.selected="first",await i(e),o(e.selected).to.equal("first"),o(a.checked,"moved to checked").to.be.true,o(d.checked).to.be.false,o(s.checked).to.be.false}),it("prioritizes checked over selected on initialization when conflicting",()=>{const e=t.querySelector("sp-radio-group#test-checked-prioritized"),a=e.querySelector("sp-radio[value=first]"),d=e.querySelector("sp-radio[value=second]");o(e.selected).to.equal("first"),o(a.checked).to.be.true,o(d.checked).to.be.false}),it("handles integer values for radio buttons",()=>{const e=t.querySelector("sp-radio-group#test-integer-value");o(e.selected).to.equal("5")}),it("prevents `change` events from radio buttons",async()=>{const e=R(),d=await r(c`
|
|
101
|
+
<sp-radio-group @change=${b=>{e(b.target.selected)}}>
|
|
400
102
|
<sp-radio value="bulbasaur">Bulbasaur</sp-radio>
|
|
401
103
|
<sp-radio value="squirtle">Squirtle</sp-radio>
|
|
402
104
|
<sp-radio value="charmander">Charmander</sp-radio>
|
|
403
105
|
</sp-radio-group>
|
|
404
|
-
`);
|
|
405
|
-
const bulbasaur = el.querySelector('[value="bulbasaur"]');
|
|
406
|
-
const charmander = el.querySelector('[value="charmander"]');
|
|
407
|
-
bulbasaur.click();
|
|
408
|
-
bulbasaur.click();
|
|
409
|
-
charmander.click();
|
|
410
|
-
expect(changeSpy.calledWith(void 0)).to.be.false;
|
|
411
|
-
});
|
|
412
|
-
});
|
|
106
|
+
`),s=d.querySelector('[value="bulbasaur"]'),p=d.querySelector('[value="charmander"]');s.click(),s.click(),p.click(),o(e.calledWith(void 0)).to.be.false})});
|
|
413
107
|
//# sourceMappingURL=radio-group.test.js.map
|