Skip to content

Commit a81328f

Browse files
committed
- RadioButtonGroup values for name/required override those of RadioButton
- Fix reactivity when RadioButton is used without group - Use `readable` when writing is not required - Use `readonly` to make intent clearer. - Remove default values for `required` and `name` - More consistent with other input types - Means that `name` attribute will not be added for no reason
1 parent 7be9e4c commit a81328f

File tree

7 files changed

+1534
-1618
lines changed

7 files changed

+1534
-1618
lines changed

COMPONENT_INDEX.md

+1,503-1,596
Large diffs are not rendered by default.

docs/src/COMPONENT_API.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -4788,7 +4788,7 @@
47884788
{
47894789
"name": "company",
47904790
"kind": "let",
4791-
"description": "Specify the company name. \nAlternatively, use the named slot \"company\" (e.g., `<span slot=\"company\">...</span>`)",
4791+
"description": "Specify the company name.\n\nAlternatively, use the named slot \"company\" (e.g., `<span slot=\"company\">...</span>`)",
47924792
"type": "string",
47934793
"isFunction": false,
47944794
"isFunctionDeclaration": false,
@@ -9463,7 +9463,6 @@
94639463
"kind": "let",
94649464
"description": "Specify a name attribute for the radio button input",
94659465
"type": "string",
9466-
"value": "\"\"",
94679466
"isFunction": false,
94689467
"isFunctionDeclaration": false,
94699468
"isRequired": false,
@@ -9528,9 +9527,9 @@
95289527
"kind": "let",
95299528
"description": "Set to `true` to require the selection of a radio button",
95309529
"type": "boolean",
9531-
"value": "false",
95329530
"isFunction": false,
95339531
"isFunctionDeclaration": false,
9532+
"isRequired": false,
95349533
"constant": false,
95359534
"reactive": false
95369535
},
@@ -9539,9 +9538,9 @@
95399538
"kind": "let",
95409539
"description": "Specify a name attribute for the radio button inputs",
95419540
"type": "string",
9542-
"value": "\"\"",
95439541
"isFunction": false,
95449542
"isFunctionDeclaration": false,
9543+
"isRequired": false,
95459544
"constant": false,
95469545
"reactive": false
95479546
},

src/RadioButton/RadioButton.svelte

+11-8
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@
2626
/** Set an id for the input element */
2727
export let id = "ccs-" + Math.random().toString(36);
2828
29-
/** Specify a name attribute for the radio button input */
30-
export let name = "";
29+
/**
30+
* Specify a name attribute for the radio button input
31+
* @type {string}
32+
*/
33+
export let name = undefined;
3134
3235
/** Obtain a reference to the input HTML element */
3336
export let ref = null;
3437
3538
import { getContext } from "svelte";
36-
import { writable } from "svelte/store";
39+
import { readable } from "svelte/store";
3740
3841
const { add, update, selectedValue, groupName, groupRequired } = getContext(
3942
"RadioButtonGroup"
4043
) ?? {
41-
groupName: writable(name),
42-
groupRequired: writable(required),
43-
selectedValue: writable(checked ? value : undefined),
44+
groupName: readable(undefined),
45+
groupRequired: readable(undefined),
46+
selectedValue: readable(checked ? value : undefined),
4447
};
4548
4649
if (add) {
@@ -59,10 +62,10 @@
5962
bind:this="{ref}"
6063
type="radio"
6164
id="{id}"
62-
name="{'name' in $$props ? name : $groupName}"
65+
name="{$groupName ?? name}"
6366
checked="{checked}"
6467
disabled="{disabled}"
65-
required="{'required' in $$props ? required : $groupRequired}"
68+
required="{$groupRequired ?? required}"
6669
value="{value}"
6770
class:bx--radio-button="{true}"
6871
on:change

src/RadioButtonGroup/RadioButtonGroup.svelte

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
/** Set to `true` to disable the radio buttons */
99
export let disabled = false;
1010
11-
/** Set to `true` to require the selection of a radio button */
12-
export let required = false;
11+
/**
12+
* Set to `true` to require the selection of a radio button
13+
* @type {boolean}
14+
*/
15+
export let required = undefined;
1316
14-
/** Specify a name attribute for the radio button inputs */
15-
export let name = "";
17+
/**
18+
* Specify a name attribute for the radio button inputs
19+
* @type {string}
20+
*/
21+
export let name = undefined;
1622
1723
/** Specify the legend text */
1824
export let legendText = "";
@@ -44,7 +50,7 @@
4450
onMount,
4551
setContext,
4652
} from "svelte";
47-
import { writable } from "svelte/store";
53+
import { readonly, writable } from "svelte/store";
4854
4955
const dispatch = createEventDispatcher();
5056
const selectedValue = writable(selected);
@@ -53,8 +59,8 @@
5359
5460
setContext("RadioButtonGroup", {
5561
selectedValue,
56-
groupName: { subscribe: groupName.subscribe },
57-
groupRequired: { subscribe: groupRequired.subscribe },
62+
groupName: readonly(groupName),
63+
groupRequired: readonly(groupRequired),
5864
add: ({ checked, value }) => {
5965
if (checked) {
6066
selectedValue.set(value);

types/RadioButton/RadioButton.svelte.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface RadioButtonProps extends RestProps {
5454

5555
/**
5656
* Specify a name attribute for the radio button input
57-
* @default ""
57+
* @default undefined
5858
*/
5959
name?: string;
6060

types/RadioButtonGroup/RadioButtonGroup.svelte.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export interface RadioButtonGroupProps extends RestProps {
1818

1919
/**
2020
* Set to `true` to require the selection of a radio button
21-
* @default false
21+
* @default undefined
2222
*/
2323
required?: boolean;
2424

2525
/**
2626
* Specify a name attribute for the radio button inputs
27-
* @default ""
27+
* @default undefined
2828
*/
2929
name?: string;
3030

types/UIShell/Header.svelte.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface HeaderProps extends RestProps {
3030

3131
/**
3232
* Specify the company name.
33+
*
3334
* Alternatively, use the named slot "company" (e.g., `<span slot="company">...</span>`)
3435
* @default undefined
3536
*/

0 commit comments

Comments
 (0)