fix(radio-button-group): add name and required props (#1037)

Fixes #1036
This commit is contained in:
brunnerh 2023-10-01 19:14:53 +02:00 committed by GitHub
commit 24e2a8874f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 98 additions and 36 deletions

View file

@ -8,6 +8,18 @@
/** Set to `true` to disable the radio buttons */
export let disabled = false;
/**
* Set to `true` to require the selection of a radio button
* @type {boolean}
*/
export let required = undefined;
/**
* Specify a name attribute for the radio button inputs
* @type {string}
*/
export let name = undefined;
/** Specify the legend text */
export let legendText = "";
@ -38,13 +50,17 @@
onMount,
setContext,
} from "svelte";
import { writable } from "svelte/store";
import { readonly, writable } from "svelte/store";
const dispatch = createEventDispatcher();
const selectedValue = writable(selected);
const groupName = writable(name);
const groupRequired = writable(required);
setContext("RadioButtonGroup", {
selectedValue,
groupName: readonly(groupName),
groupRequired: readonly(groupRequired),
add: ({ checked, value }) => {
if (checked) {
selectedValue.set(value);
@ -67,6 +83,9 @@
selected = value;
dispatch("change", value);
});
$: $groupName = name;
$: $groupRequired = required;
</script>
<!-- svelte-ignore a11y-mouse-events-have-key-events -->