mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-17 03:01:25 +00:00
Update checked for radio buttons without group.
Make radio button group `name` a required property.
This commit is contained in:
parent
1600775968
commit
6f51bdbf1b
7 changed files with 33 additions and 12 deletions
|
@ -54,6 +54,22 @@
|
|||
}
|
||||
|
||||
$: checked = $selectedValue === value;
|
||||
|
||||
function onChange() {
|
||||
if (update) {
|
||||
update(value);
|
||||
} else {
|
||||
checked = ref.checked;
|
||||
|
||||
if (name != null && name != "") {
|
||||
Array.from(document.getElementsByName(name))
|
||||
.filter((element) => element !== ref)
|
||||
.forEach((element) =>
|
||||
element.dispatchEvent(new CustomEvent("carbon:checked-change"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
@ -72,10 +88,9 @@
|
|||
value="{value}"
|
||||
class:bx--radio-button="{true}"
|
||||
on:change
|
||||
on:change="{() => {
|
||||
if (update) {
|
||||
update(value);
|
||||
}
|
||||
on:change="{onChange}"
|
||||
on:carbon:checked-change="{(e) => {
|
||||
checked = e.currentTarget.checked;
|
||||
}}"
|
||||
/>
|
||||
<label class:bx--radio-button__label="{true}" for="{id}">
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* Specify a name attribute for the radio button inputs
|
||||
* @type {string}
|
||||
*/
|
||||
export let name = undefined;
|
||||
export let name;
|
||||
|
||||
/** Specify the legend text */
|
||||
export let legendText = "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue