@internetarchive/ia-dropdown v1.3.10
<ia-dropdown> web component
Usage
import { optionInterface } from 'src/ia-dropdown';
const options = [{
id: 'option-1',
url: 'https://example.com',
selectedHandler: (option: optionInterface) => alert(option.id),
label: html`
<ia-icon-label>
<i slot="icon" class="invert-icon-at-hover">?</i>
<span>Ask Question</span>
</ia-icon-label>
`
}]
<ia-dropdown
options=${options}
displayCaret
@optionSelected=${({ detail }) => console.log('changed', detail.option )}
>
<p id="custom trigger" slot="dropdown-label">Click me to toggle options</p>
</ia-dropdown><ia-dropdown> public properties
opencontrols whether the dropdown menu is currently visible- default:
false
- default:
isDisabledcontrols whether the main button and/or caret is disabled- default:
false
- default:
displayCaretcontrols whether the dropdown caret should be present- default:
false
- default:
closeOnSelectcontrols whether selecting an option in the dropdown menu should close it- default:
false
- default:
openViaButtoncontrols whether clicking on the main button (not including the caret) should open the dropdown menu- default:
true
- default:
openViaCaretcontrols whether clicking on the main button's caret (if present) should open the dropdown menu- default:
true
- default:
includeSelectedOptioncontrols whether the currently-selected option is included in the dropdown menu- default:
false
- default:
optionsspecifies the list of items available in the dropdown menu, using the structure shown above. Onlyidandlabelare required.- default:
[] - Other menu option types can be used by setting
isCustomListtotrueand using thelistslot with a custom list component.
- default:
selectedOptionis a string specifying theidof the currently-selected option- default:
''
- default:
optionGroupis a string describing the dropdown's purpose, accessible to screen-readers only- default:
options
- default:
-
isCustomListreplaces default option list with slotlistallowing a custom list component to be used with different option type and behavior- default:
false
- default:
-
hasCustomClickHandlercontrols whether mainbutton@clickevent overridden by ancestor@clickor custom event- default:
false
- default:
-
closeOnEscapecontrols whether the dropdown menu should close when the escape key is pressed- default:
false
- default:
-
closeOnBackdropClickcontrols whether the dropdown menu should close when the backdrop is clicked- default:
false
- default:
<ia-dropdown> slots
slot="dropdown-label"the main button that opens the dropdown menu.slot="caret-up"replaces default up caret svg.- Use both
slot="caret-up"andclass="caret-up-svg"in the<svg>.
- Use both
slot="caret-down"replaces default down caret svg.- Use both
slot="caret-down"andclass="caret-down-svg"in the<svg>.
- Use both
slot="list"allows replacing default dropdown menu option type and behavior.
<ia-dropdown> events
Listens for:
closeDropdowncloses the dropdown menu
Dispatches:
optionSelectedwhen an option is selected in the dropdown menu
<ia-dropdown> CSS
CSS Vars Primary:
var(--dropdownFontSize, 1rem)var(--dropdownTextColor, #fff)var(--dropdownBgColor, #333)var(--dropdownCaretColor, #fff)var(--dropdownBorderColor, #fff)var(--dropdownBorderWidth, 1px)- Or override with:
--dropdownBorderTopWidth(similarly forRight,Bottom, andLeft)
- Or override with:
var(--dropdownBorderRadius, 4px)- Or override with
--dropdownBorderTopLeftRadius(similarly forTopRight,BottomRight, andBottomLeft)
- Or override with
var(--dropdownOffsetTop, 5px)(vertical distance between main button and dropdown)var(--dropdownButtonPadding, 0)var(--dropdownWhiteSpace, normal)(NB: setting tonowrapallows the dropdown to exceed the main button's width)
Selected:
var(--dropdownSelectedBgColor, #fff)var(--dropdownSelectedTextColor, #2c2c2c)
Hover:
var(--dropdownHoverBgColor, #fff)var(--dropdownHoverTextColor, #2c2f2c)var(--dropdownHoverTopBottomBorderColor, #333)
Dropdown list position:
var(--dropdownListPosition, absolute)(dropdown pops up over content)var(--dropdownListPosition, relative)(dropdown accordians with content)
Dropdown list z-index:
var(--dropdownListZIndex, 1)
Dropdown item padding:
var(--dropdownItemPaddingTop, 5px)(similarly forRight,Bottom, andLeft)
Main button:
var(--dropdownMainButtonPadding, 0px)var(--dropdownMainButtonBorder, none)var(--dropdownMainButtonBorderRadius, none)var(--dropdownMainButtonFlexDirection, row)(Setting tocolumnallows vertical layout)var(--dropdownMainButtonHoverBgColor, inherit)var(--dropdownMainButtonFocusBgColor, inherit)var(--dropdownMainButtonActiveBgColor, inherit)
Caret:
var(--caretWidth, 20px)var(--caretHeight, 10px)var(--caretPadding, 0)
<ia-icon-label> CSS
Top Level Classes
.invert-icon-at-hover- applies
filter: invert(1)to icon inslot[name='icon']on label hover
- applies
.invert-icon-at-selected- applies
filter: invert(1)to icon inslot[name='icon']when the element has.selectedclass.<ia-icon-label class="selected invert-icon-at-selected">
- applies
ex.
<ia-icon-label class="selected invert-icon-at-hover invert-icon-at-selected">
<i slot="icon" class="my-icon"></i> <!-- <i/> gets `filter: invert(1)` -->
<span>my label</span>
</ia-icon-label>Child Classes
truncate- applies
text-overflow: ellipsisto text in children of unnamed slot which use this class - applies
-webkit-line-clamp: 2if supported by browser
- applies
CSS Vars
var(--iconWidth, 20px)var(--iconHeight, 20px)var(--iconLabelGutterWidth, 10px)var(--hoverTextColor, #2c2c2c)var(--hoverBGColor, #fff)var(--selectedBgColor, #fff)var(--selectedTextColor, #2c2c2c)var(--iconLabelGutterWidth, 10px)var(--iconLabelFlexDirection, row)(setting tocolumnallows vertical layout)
Local Demo with web-dev-server
yarn startTo run a local development server that serves the basic demo located in demo/index.html
Testing with Web Test Runner
To run the suite of Web Test Runner tests, run
yarn run testTo run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
yarn run test:watchLinting with ESLint, Prettier, and Types
To scan the project for linting errors, run
yarn run lintYou can lint with ESLint and Prettier individually as well
yarn run lint:eslintyarn run lint:prettierTo automatically fix many linting errors, run
yarn run formatYou can format using ESLint and Prettier individually as well
yarn run format:eslintyarn run format:prettierTooling configs
For most of the tools, the configuration is in the package.json to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago