mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 11:59:34 +00:00
feat(ComboBox): selectedIndex -> selectedId (#1016)
* feat(breaking): selectedIndex -> selectedId in ComboBox * docs: update ComboBox
This commit is contained in:
parent
e11a893bee
commit
cde8a79fa8
9 changed files with 91 additions and 102 deletions
|
@ -7,17 +7,18 @@
|
|||
{ id: "2", text: "Fax" },
|
||||
];
|
||||
|
||||
let comboBox1_selectedIndex = -1;
|
||||
let comboBox2_selectedIndex = -1;
|
||||
let comboBox1_selectedId = undefined;
|
||||
let comboBox2_selectedId = undefined;
|
||||
|
||||
const formatSelected = (i) => (items[i] ? items[i].text : "N/A");
|
||||
const formatSelected = (id) =>
|
||||
items.find((item) => item.id === id)?.text ?? "N/A";
|
||||
|
||||
$: primary = formatSelected(comboBox1_selectedIndex);
|
||||
$: secondary = formatSelected(comboBox2_selectedIndex);
|
||||
$: primary = formatSelected(comboBox1_selectedId);
|
||||
$: secondary = formatSelected(comboBox2_selectedId);
|
||||
</script>
|
||||
|
||||
<ComboBox
|
||||
bind:selectedIndex="{comboBox1_selectedIndex}"
|
||||
bind:selectedId="{comboBox1_selectedId}"
|
||||
titleText="Primary contact"
|
||||
placeholder="Select primary contact method"
|
||||
items="{items}"
|
||||
|
@ -26,7 +27,7 @@
|
|||
<div>Primary: {primary}</div>
|
||||
|
||||
<ComboBox
|
||||
bind:selectedIndex="{comboBox2_selectedIndex}"
|
||||
bind:selectedId="{comboBox2_selectedId}"
|
||||
titleText="Secondary contact"
|
||||
placeholder="Select secondary contact method"
|
||||
items="{items}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue