mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
feat(dropdown): add direction prop
This commit is contained in:
parent
2fc2767acd
commit
f6c2007636
6 changed files with 36 additions and 3 deletions
|
@ -985,6 +985,7 @@ export interface DropdownItem {
|
||||||
| items | <code>let</code> | No | <code>DropdownItem[]</code> | <code>[]</code> | Set the dropdown items |
|
| items | <code>let</code> | No | <code>DropdownItem[]</code> | <code>[]</code> | Set the dropdown items |
|
||||||
| itemToString | <code>let</code> | No | <code>(item: DropdownItem) => string</code> | <code>(item) => item.text || item.id</code> | Override the display of a dropdown item |
|
| itemToString | <code>let</code> | No | <code>(item: DropdownItem) => string</code> | <code>(item) => item.text || item.id</code> | Override the display of a dropdown item |
|
||||||
| type | <code>let</code> | No | <code>"default" | "inline"</code> | <code>"default"</code> | Specify the type of dropdown |
|
| type | <code>let</code> | No | <code>"default" | "inline"</code> | <code>"default"</code> | Specify the type of dropdown |
|
||||||
|
| direction | <code>let</code> | No | <code>"bottom" | "top"</code> | <code>"bottom"</code> | Specify the direction of the dropdown menu |
|
||||||
| size | <code>let</code> | No | <code>"sm" | "lg" | "xl"</code> | -- | Specify the size of the dropdown field |
|
| size | <code>let</code> | No | <code>"sm" | "lg" | "xl"</code> | -- | Specify the size of the dropdown field |
|
||||||
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
||||||
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the dropdown |
|
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the dropdown |
|
||||||
|
|
|
@ -2320,6 +2320,16 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "direction",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Specify the direction of the dropdown menu",
|
||||||
|
"type": "\"bottom\" | \"top\"",
|
||||||
|
"value": "\"bottom\"",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "size",
|
"name": "size",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -33,6 +33,14 @@ Use the `itemToString` prop to format the display of individual items.
|
||||||
|
|
||||||
<FileSource src="/framed/Dropdown/MultipleDropdown" />
|
<FileSource src="/framed/Dropdown/MultipleDropdown" />
|
||||||
|
|
||||||
|
### Top direction
|
||||||
|
|
||||||
|
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"},
|
||||||
|
{id: "1", text: "Email"},
|
||||||
|
{id: "2", text: "Fax"}]}" />
|
||||||
|
|
||||||
### Light variant
|
### Light variant
|
||||||
|
|
||||||
<Dropdown light titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
<Dropdown light titleText="Contact" selectedIndex={0} items="{[{id: "0", text: "Slack"},
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
*/
|
*/
|
||||||
export let type = "default";
|
export let type = "default";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the direction of the dropdown menu
|
||||||
|
* @type {"bottom" | "top"}
|
||||||
|
*/
|
||||||
|
export let direction = "bottom";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the size of the dropdown field
|
* Specify the size of the dropdown field
|
||||||
* @type {"sm" | "lg" | "xl"}
|
* @type {"sm" | "lg" | "xl"}
|
||||||
|
@ -105,8 +111,8 @@
|
||||||
let selectedId = undefined;
|
let selectedId = undefined;
|
||||||
let highlightedIndex = -1;
|
let highlightedIndex = -1;
|
||||||
|
|
||||||
function change(direction) {
|
function change(dir) {
|
||||||
let index = highlightedIndex + direction;
|
let index = highlightedIndex + dir;
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = items.length - 1;
|
index = items.length - 1;
|
||||||
|
@ -159,7 +165,8 @@
|
||||||
id="{id}"
|
id="{id}"
|
||||||
name="{name}"
|
name="{name}"
|
||||||
aria-label="{$$props['aria-label']}"
|
aria-label="{$$props['aria-label']}"
|
||||||
class="bx--dropdown {invalid && 'bx--dropdown--invalid'} {!invalid &&
|
class="bx--dropdown {direction === 'top' && 'bx--list-box--up'} {invalid &&
|
||||||
|
'bx--dropdown--invalid'} {!invalid &&
|
||||||
warn &&
|
warn &&
|
||||||
'bx--dropdown--warning'} {open && 'bx--dropdown--open'}
|
'bx--dropdown--warning'} {open && 'bx--dropdown--open'}
|
||||||
{size ===
|
{size ===
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
direction="top"
|
||||||
titleText="Contact"
|
titleText="Contact"
|
||||||
selectedIndex="{0}"
|
selectedIndex="{0}"
|
||||||
items="{[
|
items="{[
|
||||||
|
|
6
types/Dropdown/Dropdown.d.ts
vendored
6
types/Dropdown/Dropdown.d.ts
vendored
|
@ -36,6 +36,12 @@ export interface DropdownProps
|
||||||
*/
|
*/
|
||||||
type?: "default" | "inline";
|
type?: "default" | "inline";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the direction of the dropdown menu
|
||||||
|
* @default "bottom"
|
||||||
|
*/
|
||||||
|
direction?: "bottom" | "top";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the size of the dropdown field
|
* Specify the size of the dropdown field
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue