diff --git a/documents/src/pages/elements/select.md b/documents/src/pages/elements/select.md index e3f0e84e5d..52f0881404 100644 --- a/documents/src/pages/elements/select.md +++ b/documents/src/pages/elements/select.md @@ -22,41 +22,26 @@ ef-select { ``` ```html
- - Drinks - Cola - Apple Juice - Iced Tea - Ice Cream - Vanilla - Chocolate - Honey & Walnut - Raspberry - - - - Drinks - Cola - Apple Juice - Iced Tea - Ice Cream - Vanilla - Chocolate - Honey & Walnut - Raspberry - - - Lemonade - + + + Drinks + Cola + Apple Juice + Iced Tea + Ice Cream + Vanilla Ice Cream + Chocolate Ice Cream + Honey & Walnut Ice Cream + Raspberry Ice Cream
``` :: ## Usage -`ef-select` expands upon the native `select` element, providing a fully themeable dropdown element. +`ef-select` expands upon the native `select` element, providing a fully themeable dropdown element. There are 2 ways to create options for `ef-select`. -Choices can be defined using `ef-item`. +### Using `ef-item` :: ```javascript @@ -65,84 +50,75 @@ Choices can be defined using `ef-item`. ```css section { height: 155px; - padding: 0 3px; +} +ef-select { + width: 160px; + margin-left: 4px; } ``` ```html
- - Cola - Lemonade - Orange Juice - Apple Juice - Iced Tea + + + Apple + Papaya + Banana + Orange
``` :: ```html - - Cola - Lemonade - Orange Juice - Apple Juice - Iced Tea + + + Apple + Papaya + Banana + Orange ``` -## Data property interface +### Using `data` property The `data` property of the `ef-select` uses the [SelectData](https://github.com/Refinitiv/refinitiv-ui/blob/v6/packages/elements/src/select/helpers/types.ts) type for its data items. Each item is `ItemData` type extended from [DataItem](./custom-components/utils/data-management#data-item). -## Categorize into groups - -Groups are also defined using `ef-item`. The only difference is that we add a `type="header"` attribute onto the element. - -:: ```javascript -::select:: -``` -```css -section { - height: 250px; - padding: 0 3px; -} -``` -```html -
- - Drinks - Cola - Lemonade - Water - Ice Cream - Vanilla - Chocolate - Strawberry - Raspberry - -
-``` -:: - -``` html - - Drinks - Cola - Lemonade - Water - Ice Cream - Vanilla - Chocolate - Strawberry - Raspberry - +const select = document.querySelector('ef-select'); +const data = [ + { + label: 'Drinks', + type: 'header' + }, + { + label: 'Tea', + value: 'tea' + }, + { + label: 'Beer', + value: 'beer', + selected: true + }, + { + label: 'Ice Cream', + type: 'header' + }, + { + label: 'Vanilla', + value: 'vanilla', + disabled: true + }, + { + label: 'Strawberry', + value: 'Strawberry' + } +]; +select.data = data; ``` -## Adding a placeholder +## Categorize into groups -Once you have your choices and groups defined, you can then add placeholder text to help users understand what the list contains and what their choice is for. +Groups are also defined using `ef-item`. The only difference is that we add a `type="header"` attribute onto the element. :: ```javascript @@ -150,26 +126,37 @@ Once you have your choices and groups defined, you can then add placeholder text ``` ```css section { - height: 155px; - padding: 0 3px; + height: 275px; +} +ef-select { + margin-left: 4px; } ``` ```html
- - Cola - Lemonade - Orange Juice - Apple Juice - Iced Tea + + + Asia + Japan + Singapore + Thailand + Europe + London + Italy + America + USA
``` :: ``` html - + + Asia ... + Europe + ... + ``` ## Selecting a default option @@ -184,21 +171,19 @@ Only one option can be selected at a time. ``` ```css section { - height: 225px; - padding: 0 3px; + height: 130px; +} +ef-select { + margin-left: 4px; } ``` ```html
- - Drinks - Cola - Lemonade - Water - Ice Cream - Vanilla - Strawberry - Raspberry + + + Black + Blue + Green
``` @@ -206,7 +191,7 @@ section { ```html ... - Water + Green ... ``` @@ -220,20 +205,22 @@ Options can be disabled by adding a `disabled` attribute to the options you wish ``` ```css section { - height: 200px; - padding: 0 3px; + height: 170px; +} +ef-select { + margin-left: 4px; } ``` ```html
- - Drinks - Apple Juice - Iced Tea - Water - Ice Cream - Vanilla - Chocolate + + + XS + S + M (Out of stock) + L + XL + 2XL
``` @@ -241,93 +228,10 @@ section { ```html ... - Iced Tea - Water + M (Out of stock) ... ``` -## Configuring options using data object - -Depending on your usage, you may wish to configure `ef-select` using its `data` object. - -:: -```javascript -::select:: -const el = document.querySelector("ef-select"); -el.data = [ - { - label: 'Drinks', - type: 'header' - }, - { - label: 'Tea', - value: 'tea' - }, - { - label: 'Beer', - value: 'beer', - selected: true - }, - { - label: 'Ice Cream', - type: 'header' - }, - { - label: 'Vanilla', - value: 'vanilla', - disabled: true - }, - { - label: 'Strawberry', - value: 'Strawberry' - } -]; -``` -```css -section { - height: 180px; - padding: 0 3px; -} -``` -```html -
- -
-``` -:: - -```javascript -const el = document.querySelector("ef-select"); -el.data = [ - { - label: 'Drinks', - type: 'header' - }, - { - label: 'Tea', - value: 'tea' - }, - { - label: 'Beer', - value: 'beer', - selected: true - }, - { - label: 'Ice Cream', - type: 'header' - }, - { - label: 'Vanilla', - value: 'vanilla', - disabled: true - }, - { - label: 'Strawberry', - value: 'Strawberry' - } -]; -``` - ## Restricting list height The `max-height` of the list can be restricted using the `--list-max-height` property. @@ -339,22 +243,23 @@ The `max-height` of the list can be restricted using the `--list-max-height` pro ```css section { height: 130px; - padding: 0 3px; } ef-select { + margin-left: 4px; --list-max-height: 100px; } ``` ```html
- - Drinks - Apple Juice - Iced Tea - Water - Ice Cream - Vanilla - Chocolate + + + Drinks + Apple Juice + Iced Tea + Water + Ice Cream + Vanilla + Chocolate
``` @@ -385,13 +290,14 @@ ef-select { ## Accessibility ::a11y-intro:: -`ef-select` is assigned `role="button"` and also attribute `aria-expanded`. Select options are assigned `role="option"` and `aria-selected` which depends on item's selection state. +`ef-select` is assigned `role="combobox"` and also attribute `aria-expanded`. Select options are assigned `role="option"` and `aria-selected` which depends on item's selection state. You must ensure that the element has associated label by using `aria-label`, `aria-labelledby` or `label[for=""]`. * `ef-select` manages the role and aria attributes automatically if you create `ef-select` using `data` property -* If you create select declaratively by using `ef-item`, assign `role="option"` to selectable `ef-item`. +* If you create select declaratively by using `ef-item`, assign `role="option"` to selectable `ef-item` and `role="presentation"` to `ef-item` with `type="header"` and `type="divider"`. ```html - + + GBP (£) EUR (€) USD ($) @@ -400,17 +306,12 @@ ef-select { * If you have header items, assign `role="presentation"` on the items ```html - + + Drinks - Cola - Lemonade - Iced Tea - Water + ... Ice Cream - Vanilla - Chocolate - Pistachio - Salted Caramel + ... ``` diff --git a/packages/elements/src/select/__demo__/index.html b/packages/elements/src/select/__demo__/index.html index 21f246db53..29987945f8 100644 --- a/packages/elements/src/select/__demo__/index.html +++ b/packages/elements/src/select/__demo__/index.html @@ -15,32 +15,49 @@ import '@refinitiv-ui/demo-block'; + + - - Drinks - Cola - Lemonade - Orange Juice - Apple Juice - Iced Tea - Water - Ice Cream - Vanilla - Chocolate - Honey & Walnut - Pistachio - Salted Caramel - Mint Choc Chip - Hazelnut - Strawberry - Raspberry - +
+ + + Drinks + Cola + Lemonade + Orange Juice + Apple Juice + Iced Tea + Water + Ice Cream + Vanilla + Chocolate + Honey & Walnut + Pistachio + Salted Caramel + Mint Choc Chip + Hazelnut + Strawberry + Raspberry + +
- - GBP (£) - EUR (€) - USD ($) - +
+ + + GBP (£) + EUR (€) + USD ($) + +