Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate name and required from TileGroup. #973

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Tile/RadioTile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
/** Set an id for the input element */
export let id = "ccs-" + Math.random().toString(36);

/** Specify a name attribute for the input */
export let name = "";

import { getContext } from "svelte";
import CheckmarkFilled16 from "../icons/CheckmarkFilled16.svelte";

const { add, update, selectedValue } = getContext("TileGroup");
const { add, update, selectedValue, name, required } =
getContext("TileGroup");

add({ value, checked });

Expand All @@ -36,11 +34,12 @@
<input
type="radio"
id="{id}"
name="{name}"
name="{$name}"
value="{value}"
checked="{checked}"
tabindex="{disabled ? undefined : tabindex}"
disabled="{disabled}"
required="{$required}"
class:bx--tile-input="{true}"
on:change
on:change="{() => {
Expand Down
15 changes: 15 additions & 0 deletions src/Tile/TileGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
/** Set to `true` to disable the tile group */
export let disabled = false;

/**
* Set to `true` to mark the selection as required.
* For validation to trigger, a `name` has to be specified as well.
*/
export let required = false;

/** Specify a name attribute for the radio inputs */
export let name = "";

/** Specify the legend text */
export let legend = "";

Expand All @@ -16,9 +25,13 @@

const dispatch = createEventDispatcher();
const selectedValue = writable(selected);
const inputsName = writable(name);
const inputsRequired = writable(required);

setContext("TileGroup", {
selectedValue,
name: { subscribe: inputsName.subscribe },
required: { subscribe: inputsRequired.subscribe },
add: ({ checked, value }) => {
if (checked) {
selectedValue.set(value);
Expand All @@ -32,6 +45,8 @@

$: selected = $selectedValue;
$: selectedValue.set(selected);
$: inputsName.set(name);
$: inputsRequired.set(required);
</script>

<fieldset disabled="{disabled}" class:bx--tile-group="{true}" {...$$restProps}>
Expand Down