@warp-ds/elements 2.8.1-next.4 → 2.8.1

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.
@@ -1,3 +1,4 @@
1
+ import { html } from 'lit';
1
2
  import './switch.js';
2
3
  const meta = {
3
4
  title: 'Forms/Switch',
@@ -33,3 +34,53 @@ export const DisabledChecked = {
33
34
  disabled: true,
34
35
  },
35
36
  };
37
+ export const WithLabel = {
38
+ render: () => html `
39
+ <div style="display: inline-flex; align-items: center; gap: 8px;">
40
+ <span id="switch-label">Enable notifications</span>
41
+ <w-switch aria-labelledby="switch-label"></w-switch>
42
+ </div>
43
+ `,
44
+ };
45
+ export const NativeLabel = {
46
+ render: () => html `
47
+ <div style="display: inline-flex; align-items: center; gap: 8px;">
48
+ <label for="native-label-switch">Enable notifications</label>
49
+ <w-switch
50
+ id="native-label-switch"
51
+ name="notifications"
52
+ value="enabled"
53
+ ></w-switch>
54
+ </div>
55
+ `,
56
+ };
57
+ export const SwitchFormAssociated = {
58
+ render: () => {
59
+ const handleSubmit = (event) => {
60
+ event.preventDefault();
61
+ const form = event.currentTarget;
62
+ const status = form.querySelector('[data-status]');
63
+ if (!status)
64
+ return;
65
+ const data = new FormData(form);
66
+ const name = 'notifications';
67
+ const value = data.get(name);
68
+ status.textContent =
69
+ value === null ? 'Submitted: no switch value captured.' : `Submitted: ${name}=${String(value)}`;
70
+ };
71
+ return html `
72
+ <form @submit=${handleSubmit} style="display: grid; gap: 12px; max-width: 320px;">
73
+ <div style="display: inline-flex; align-items: center; gap: 8px;">
74
+ <span id="switch-form-label">Enable notifications</span>
75
+ <w-switch
76
+ aria-labelledby="switch-form-label"
77
+ name="notifications"
78
+ value="enabled"
79
+ ></w-switch>
80
+ </div>
81
+ <button type="submit">Submit</button>
82
+ <div data-status aria-live="polite"></div>
83
+ </form>
84
+ `;
85
+ },
86
+ };
@@ -38,3 +38,38 @@ test('can reset switch by resetting surrounding form', async () => {
38
38
  const data3 = new FormData(form);
39
39
  expect(Array.from(data3.entries()).length).toBe(1);
40
40
  });
41
+ test('mouse click toggles switch once', async () => {
42
+ render(html `<w-switch aria-label="Enable notifications"></w-switch>`);
43
+ const wSwitch = document.querySelector('w-switch');
44
+ await wSwitch.updateComplete;
45
+ const button = wSwitch.shadowRoot.querySelector('button');
46
+ expect(wSwitch.checked).toBe(false);
47
+ expect(wSwitch.getAttribute('aria-checked')).toBe('false');
48
+ button.click();
49
+ await wSwitch.updateComplete;
50
+ expect(wSwitch.checked).toBe(true);
51
+ expect(wSwitch.getAttribute('aria-checked')).toBe('true');
52
+ });
53
+ test('native label click toggles switch', async () => {
54
+ render(html `
55
+ <label for="native-label-switch">Enable notifications</label>
56
+ <w-switch
57
+ id="native-label-switch"
58
+ name="notifications"
59
+ value="enabled"
60
+ ></w-switch>
61
+ `);
62
+ const label = document.querySelector('label');
63
+ const wSwitch = document.querySelector('w-switch');
64
+ await wSwitch.updateComplete;
65
+ expect(wSwitch.checked).toBe(false);
66
+ expect(wSwitch.getAttribute('aria-checked')).toBe('false');
67
+ label.click();
68
+ await wSwitch.updateComplete;
69
+ expect(wSwitch.checked).toBe(true);
70
+ expect(wSwitch.getAttribute('aria-checked')).toBe('true');
71
+ label.click();
72
+ await wSwitch.updateComplete;
73
+ expect(wSwitch.checked).toBe(false);
74
+ expect(wSwitch.getAttribute('aria-checked')).toBe('false');
75
+ });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "name": "@warp-ds/elements",
4
- "version": "2.8.1-next.3",
4
+ "version": "2.8.1-next.5",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -1185,42 +1185,32 @@
1185
1185
  },
1186
1186
  {
1187
1187
  "name": "w-radio-group",
1188
- "description": "\n---\n\n\n### **Methods:**\n - **focus(options: _FocusOptions_)** - Sets focus on the radio group.\n\n### **Slots:**\n - **label** - Alternative to the `label` attribute should you need custom HTML.\n- **help-text** - Alternative to the `help-text` attribute should you need custom HTML.",
1188
+ "description": "\n---\n\n\n### **Slots:**\n - **label** - Alternative to the `label` attribute should you need custom HTML.\n- **help-text** - Alternative to the `help-text` attribute should you need custom HTML.",
1189
1189
  "doc-url": "",
1190
1190
  "attributes": [
1191
- {
1192
- "name": "label",
1193
- "description": "The radio group's label. Required for proper accessibility. If you need to display HTML, use the `label` slot\ninstead.",
1194
- "value": { "type": "string", "default": "''" }
1195
- },
1191
+ { "name": "label", "value": { "type": "string", "default": "''" } },
1196
1192
  {
1197
1193
  "name": "help-text",
1198
- "description": "The radio group's help text. If you need to display HTML, use the `help-text` slot instead.",
1199
1194
  "value": { "type": "string", "default": "''" }
1200
1195
  },
1201
1196
  {
1202
1197
  "name": "optional",
1203
- "description": "Optional indicator for the label.",
1204
1198
  "value": { "type": "boolean", "default": "false" }
1205
1199
  },
1206
1200
  {
1207
1201
  "name": "invalid",
1208
- "description": "Marks the radio group as invalid.",
1209
1202
  "value": { "type": "boolean", "default": "false" }
1210
1203
  },
1211
1204
  {
1212
1205
  "name": "name",
1213
- "description": "The name of the radio group",
1214
1206
  "value": { "type": "string | null", "default": "null" }
1215
1207
  },
1216
1208
  {
1217
1209
  "name": "disabled",
1218
- "description": "Disables the radio group and all child radios.",
1219
1210
  "value": { "type": "boolean", "default": "false" }
1220
1211
  },
1221
1212
  {
1222
1213
  "name": "required",
1223
- "description": "Ensures a child radio is checked before allowing the containing form to submit.",
1224
1214
  "value": { "type": "boolean", "default": "false" }
1225
1215
  }
1226
1216
  ],
@@ -1238,45 +1228,14 @@
1238
1228
  "js": {
1239
1229
  "properties": [
1240
1230
  { "name": "hasInteracted", "type": "boolean" },
1241
- {
1242
- "name": "label",
1243
- "description": "The radio group's label. Required for proper accessibility. If you need to display HTML, use the `label` slot\ninstead.",
1244
- "type": "string"
1245
- },
1246
- {
1247
- "name": "helpText",
1248
- "description": "The radio group's help text. If you need to display HTML, use the `help-text` slot instead.",
1249
- "type": "string"
1250
- },
1251
- {
1252
- "name": "optional",
1253
- "description": "Optional indicator for the label.",
1254
- "type": "boolean"
1255
- },
1256
- {
1257
- "name": "invalid",
1258
- "description": "Marks the radio group as invalid.",
1259
- "type": "boolean"
1260
- },
1261
- {
1262
- "name": "name",
1263
- "description": "The name of the radio group",
1264
- "type": "string | null"
1265
- },
1266
- {
1267
- "name": "disabled",
1268
- "description": "Disables the radio group and all child radios.",
1269
- "type": "boolean"
1270
- },
1271
- {
1272
- "name": "required",
1273
- "description": "Ensures a child radio is checked before allowing the containing form to submit.",
1274
- "type": "boolean"
1275
- },
1276
- {
1277
- "name": "validationTarget",
1278
- "description": "We use the first available radio as the validationTarget similar to native HTML that shows the validation popup on\nthe first radio element."
1279
- }
1231
+ { "name": "label", "type": "string" },
1232
+ { "name": "helpText", "type": "string" },
1233
+ { "name": "optional", "type": "boolean" },
1234
+ { "name": "invalid", "type": "boolean" },
1235
+ { "name": "name", "type": "string | null" },
1236
+ { "name": "disabled", "type": "boolean" },
1237
+ { "name": "required", "type": "boolean" },
1238
+ { "name": "validationTarget" }
1280
1239
  ],
1281
1240
  "events": []
1282
1241
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warp-ds/elements",
3
3
  "type": "module",
4
- "version": "2.8.1-next.4",
4
+ "version": "2.8.1",
5
5
  "packageManager": "pnpm@10.30.3",
6
6
  "description": "Custom elements for Warp",
7
7
  "exports": {