Skip to content

Commit fc515c5

Browse files
committed
fix(tile-group): add name and required props
1 parent 5ef4dc1 commit fc515c5

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Tile/RadioTile.svelte

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
/** Set to `true` to disable the tile */
99
export let disabled = false;
1010
11+
/** Set to `true` to mark the field as required */
12+
export let required = false;
13+
1114
/** Specify the value of the radio input */
1215
export let value = "";
1316
@@ -23,10 +26,16 @@
2326
/** Specify a name attribute for the input */
2427
export let name = "";
2528
26-
import { getContext } from "svelte";
29+
import { getContext, readable } from "svelte";
2730
import CheckmarkFilled from "../icons/CheckmarkFilled.svelte";
2831
29-
const { add, update, selectedValue } = getContext("TileGroup");
32+
const { add, update, selectedValue, groupName, groupRequired } = getContext(
33+
"TileGroup"
34+
) ?? {
35+
groupName: readable(undefined),
36+
groupRequired: readable(undefined),
37+
selectedValue: readable(checked ? value : undefined),
38+
};
3039
3140
add({ value, checked });
3241
@@ -36,11 +45,12 @@
3645
<input
3746
type="radio"
3847
id="{id}"
39-
name="{name}"
48+
name="{$groupName ?? name}"
4049
value="{value}"
4150
checked="{checked}"
4251
tabindex="{disabled ? undefined : tabindex}"
4352
disabled="{disabled}"
53+
required="{$groupRequired ?? required}"
4454
class:bx--tile-input="{true}"
4555
on:change
4656
on:change="{() => {

src/Tile/TileGroup.svelte

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,31 @@
88
/** Set to `true` to disable the tile group */
99
export let disabled = false;
1010
11+
/**
12+
* Set to `true` to require the selection of a radio button
13+
* @type {boolean}
14+
*/
15+
export let required = undefined;
16+
17+
/**
18+
* Specify a name attribute for the radio button inputs
19+
* @type {string}
20+
*/
21+
export let name = undefined;
22+
1123
/** Specify the legend text */
1224
export let legend = "";
1325
1426
import { createEventDispatcher, setContext } from "svelte";
15-
import { writable } from "svelte/store";
27+
import { writable, readonly } from "svelte/store";
1628
1729
const dispatch = createEventDispatcher();
1830
const selectedValue = writable(selected);
1931
2032
setContext("TileGroup", {
2133
selectedValue,
34+
groupName: readonly(groupName),
35+
groupRequired: readonly(groupRequired),
2236
add: ({ checked, value }) => {
2337
if (checked) {
2438
selectedValue.set(value);

0 commit comments

Comments
 (0)