mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix(select): do not dispatch "change" event on initial load (#1356)
Follow-up to #1353 If `selected` is `undefined` or not provided, the "change" event will be dispatched since the first `SelectItem` value will be set as the default. The "change" event should only be dispatched when the value is actually changed.
This commit is contained in:
parent
b4d0205080
commit
511d7c24e6
1 changed files with 8 additions and 1 deletions
|
@ -108,9 +108,16 @@
|
||||||
selectedValue.set(value);
|
selectedValue.set(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let prevSelected = undefined;
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
selected = $selectedValue;
|
selected = $selectedValue;
|
||||||
dispatch("change", $selectedValue);
|
|
||||||
|
if (prevSelected !== undefined && selected !== prevSelected) {
|
||||||
|
dispatch("change", $selectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
prevSelected = selected;
|
||||||
});
|
});
|
||||||
|
|
||||||
$: errorId = `error-${id}`;
|
$: errorId = `error-${id}`;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue