mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
Propagate name
and required
from TileGroup.
Remove `name` from `RadioTile`.
This commit is contained in:
parent
31a11e6800
commit
7579028246
2 changed files with 19 additions and 5 deletions
|
@ -20,13 +20,11 @@
|
||||||
/** Set an id for the input element */
|
/** Set an id for the input element */
|
||||||
export let id = "ccs-" + Math.random().toString(36);
|
export let id = "ccs-" + Math.random().toString(36);
|
||||||
|
|
||||||
/** Specify a name attribute for the input */
|
|
||||||
export let name = "";
|
|
||||||
|
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
import CheckmarkFilled16 from "../icons/CheckmarkFilled16.svelte";
|
import CheckmarkFilled16 from "../icons/CheckmarkFilled16.svelte";
|
||||||
|
|
||||||
const { add, update, selectedValue } = getContext("TileGroup");
|
const { add, update, selectedValue, name, required } =
|
||||||
|
getContext("TileGroup");
|
||||||
|
|
||||||
add({ value, checked });
|
add({ value, checked });
|
||||||
|
|
||||||
|
@ -36,11 +34,12 @@
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
id="{id}"
|
id="{id}"
|
||||||
name="{name}"
|
name="{$name}"
|
||||||
value="{value}"
|
value="{value}"
|
||||||
checked="{checked}"
|
checked="{checked}"
|
||||||
tabindex="{disabled ? undefined : tabindex}"
|
tabindex="{disabled ? undefined : tabindex}"
|
||||||
disabled="{disabled}"
|
disabled="{disabled}"
|
||||||
|
required="{$required}"
|
||||||
class:bx--tile-input="{true}"
|
class:bx--tile-input="{true}"
|
||||||
on:change
|
on:change
|
||||||
on:change="{() => {
|
on:change="{() => {
|
||||||
|
|
|
@ -8,6 +8,15 @@
|
||||||
/** Set to `true` to disable the tile group */
|
/** Set to `true` to disable the tile group */
|
||||||
export let disabled = false;
|
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 */
|
/** Specify the legend text */
|
||||||
export let legend = "";
|
export let legend = "";
|
||||||
|
|
||||||
|
@ -16,9 +25,13 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
const selectedValue = writable(selected);
|
const selectedValue = writable(selected);
|
||||||
|
const inputsName = writable(name);
|
||||||
|
const inputsRequired = writable(required);
|
||||||
|
|
||||||
setContext("TileGroup", {
|
setContext("TileGroup", {
|
||||||
selectedValue,
|
selectedValue,
|
||||||
|
name: { subscribe: inputsName.subscribe },
|
||||||
|
required: { subscribe: inputsRequired.subscribe },
|
||||||
add: ({ checked, value }) => {
|
add: ({ checked, value }) => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
selectedValue.set(value);
|
selectedValue.set(value);
|
||||||
|
@ -30,6 +43,8 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$: selected = $selectedValue;
|
$: selected = $selectedValue;
|
||||||
|
$: inputsName.set(name);
|
||||||
|
$: inputsRequired.set(required);
|
||||||
$: dispatch("select", $selectedValue);
|
$: dispatch("select", $selectedValue);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue