mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(Dropdown): selectedIndex -> selectedId (#1004)
* feat(breaking): selectedIndex -> selectedId in Dropdown * feat: omit `selectedIndex` from the `select` event
This commit is contained in:
parent
37f10ad1a2
commit
e11a893bee
7 changed files with 53 additions and 52 deletions
|
@ -3008,11 +3008,10 @@
|
|||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "selectedIndex",
|
||||
"name": "selectedId",
|
||||
"kind": "let",
|
||||
"description": "Specify the selected item index",
|
||||
"type": "number",
|
||||
"value": "-1",
|
||||
"description": "Specify the selected item id",
|
||||
"type": "DropdownItemId",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"constant": false,
|
||||
|
@ -3229,7 +3228,7 @@
|
|||
{
|
||||
"type": "dispatched",
|
||||
"name": "select",
|
||||
"detail": "{ selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem }"
|
||||
"detail": "{ selectedId: DropdownItemId, selectedItem: DropdownItem }"
|
||||
}
|
||||
],
|
||||
"typedefs": [
|
||||
|
|
|
@ -9,13 +9,13 @@ components: ["Dropdown", "DropdownSkeleton"]
|
|||
|
||||
### Default
|
||||
|
||||
<Dropdown titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Hidden label
|
||||
|
||||
<Dropdown hideLabel titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown hideLabel titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
|
@ -25,7 +25,7 @@ Use the `itemToString` prop to format the display of individual items.
|
|||
|
||||
<Dropdown itemToString={item => {
|
||||
return item.text + ' (' + item.id +')'
|
||||
}} titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
}} titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
|
@ -37,49 +37,49 @@ Use the `itemToString` prop to format the display of individual items.
|
|||
|
||||
Set `direction` to `"top"` for the dropdown menu to appear above the input.
|
||||
|
||||
<Dropdown direction="top" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown direction="top" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Light variant
|
||||
|
||||
<Dropdown light titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown light titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Inline variant
|
||||
|
||||
<Dropdown type="inline" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown type="inline" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Extra-large size
|
||||
|
||||
<Dropdown size="xl" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown size="xl" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Small size
|
||||
|
||||
<Dropdown size="sm" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown size="sm" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Invalid state
|
||||
|
||||
<Dropdown invalid invalidText="Secondary contact method must be different from the primary contact" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown invalid invalidText="Secondary contact method must be different from the primary contact" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Warning state
|
||||
|
||||
<Dropdown warn warnText="This contact method is not associated with your account" titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown warn warnText="This contact method is not associated with your account" titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
### Disabled state
|
||||
|
||||
<Dropdown disabled titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||
<Dropdown disabled titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}]}" />
|
||||
|
||||
|
|
|
@ -7,28 +7,29 @@
|
|||
{ id: "2", text: "Fax" },
|
||||
];
|
||||
|
||||
let dropdown1_selectedIndex = 0;
|
||||
let dropdown2_selectedIndex = 1;
|
||||
let dropdown1_selectedId = "0";
|
||||
let dropdown2_selectedId = "1";
|
||||
|
||||
const formatSelected = (i) => (items[i] ? items[i].text : "N/A");
|
||||
const formatSelected = (id) =>
|
||||
items.find((item) => item.id === id)?.text ?? "N/A";
|
||||
|
||||
$: primary = formatSelected(dropdown1_selectedIndex);
|
||||
$: secondary = formatSelected(dropdown2_selectedIndex);
|
||||
$: primary = formatSelected(dropdown1_selectedId);
|
||||
$: secondary = formatSelected(dropdown2_selectedId);
|
||||
</script>
|
||||
|
||||
<Dropdown
|
||||
titleText="Primary contact"
|
||||
bind:selectedIndex="{dropdown1_selectedIndex}"
|
||||
bind:selectedId="{dropdown1_selectedId}"
|
||||
items="{items}"
|
||||
/>
|
||||
|
||||
<div>Primary: {primary}</div>
|
||||
|
||||
<Dropdown
|
||||
invalid="{dropdown1_selectedIndex === dropdown2_selectedIndex}"
|
||||
invalid="{dropdown1_selectedId === dropdown2_selectedId}"
|
||||
invalidText="Secondary contact method must be different from the primary contact"
|
||||
titleText="Secondary contact"
|
||||
bind:selectedIndex="{dropdown2_selectedIndex}"
|
||||
bind:selectedId="{dropdown2_selectedId}"
|
||||
items="{items}"
|
||||
/>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue