mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
fix(select): subscribe to store
This commit is contained in:
parent
5e26510f43
commit
0ea98b1447
3 changed files with 28 additions and 22 deletions
|
@ -1,24 +1,28 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let value = '';
|
||||
export let text = '';
|
||||
export let disabled = false;
|
||||
export let hidden = false;
|
||||
export let style = undefined;
|
||||
export let text = '';
|
||||
export let value = '';
|
||||
|
||||
import { getContext } from 'svelte';
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const ctx = getContext('Select') || getContext('TimePickerSelect');
|
||||
|
||||
let selected = false;
|
||||
|
||||
const unsubscribe = ctx.selectedValue.subscribe(currentValue => {
|
||||
if (currentValue === value) {
|
||||
selected = true;
|
||||
}
|
||||
});
|
||||
|
||||
unsubscribe();
|
||||
</script>
|
||||
|
||||
<option
|
||||
selected={ctx.$selected === value}
|
||||
class={cx('--select-option', className)}
|
||||
{value}
|
||||
{disabled}
|
||||
{hidden}
|
||||
{style}>
|
||||
<option class={cx('--select-option', className)} {value} {disabled} {hidden} {style} {selected}>
|
||||
{text}
|
||||
</option>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue