Gathering detailed insights and metrics for react-dropdown-aria
Gathering detailed insights and metrics for react-dropdown-aria
Gathering detailed insights and metrics for react-dropdown-aria
Gathering detailed insights and metrics for react-dropdown-aria
npm install react-dropdown-aria
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
15 Stars
272 Commits
11 Forks
2 Watching
30 Branches
5 Contributors
Updated on 06 Nov 2024
Minified
Minified + Gzipped
TypeScript (95.47%)
JavaScript (4.53%)
Cumulative downloads
Total Downloads
Last day
-41.8%
346
Compared to previous day
Last week
13.7%
2,891
Compared to previous week
Last month
-2.9%
12,732
Compared to previous month
Last year
145.6%
133,168
Compared to previous year
3
40
This component was created to be a light weight and fully accessible dropdown component for React. For a more feature heavy and powerful dropdown look to the react-select package. (This dropdown is inspired by react-select)
Please take note when upgrading from v2 to v3 there are breaking changes. Be sure to carefully read the changelog entry for v3.0.0.
For demo and examples see https://jfangrad.github.io/react-dropdown-aria/
Simply use npm or yarn to install the package.
// Yarn
$ yarn add react-dropdown-aria styled-components
// npm
$ npm install --save react-dropdown-aria styled-components
You can then include it in your project as needed:
1import Dropdown from 'react-dropdown-aria';
Options should be provided to the Dropdown as an array of objects.
1<Dropdown 2 ... 3 options: {[ 4 { value: 'one' }, 5 { value: 'two' }, 6 { value: 'three' } 7 ]} 8/>
Each option object in the array of options can have the following keys:
key | Type | Default | Description |
---|---|---|---|
ariaLabel | string | null | Aria Label to be applied to the option |
className | string | null | CSS class to be applied to this option |
title | string | null | HTML title to be used for the option |
value | string | null | The value to be displayed in the dropdown (Required) |
Groups of items can also be implemented by pasing an array of objects of the following form to the dropdown options prop:
1<Dropdown 2 ... 3 options: {[ 4 { label: 'Group 1', groupOptions: optionsGroup1 }, 5 { label: 'Group 2', groupOptions: optionsGroup2 }, 6 ]} 7/>
Where the groupOptions
is an array of options as described above, and the label
is the string to display above the group in the dropdown.
Custom styling can be applied to the dropdown through 2 ways:
theme
prop (Example)The suggested method is by using the theme prop as shown in the Custom Styling Example. The theme prop can have keys of the following form:
1type RdaTheme = { 2 wrapper?: ThemeObjectOrFunction<DropdownWrapperProps>; 3 selector?: ThemeObjectOrFunction<DropdownSelectorProps>; 4 selectorSearch?: ThemeObjectOrFunction; 5 selectedValue?: ThemeObjectOrFunction<SelectedValueProps>; 6 placeholder?: ThemeObjectOrFunction<PlaceholderProps>; 7 arrow?: ThemeObjectOrFunction<ArrowProps>; 8 optionContainer?: ThemeObjectOrFunction<OptionContainerProps>; 9 groupContainer?: ThemeObjectOrFunction; 10 groupHeading?: ThemeObjectOrFunction; 11 groupDivider?: ThemeObjectOrFunction; 12 optionItem?: ThemeObjectOrFunction<OptionItemWrapProps>; 13};
As is shown above, each key in the theme
object can be either a plain object or function. If you need access to the current state of the dropdown then you should pass a function which will be called with the appropiate state.
The theme object you provide will be merged with the default theme.
If you would prefer to use option 3, you can apply styles to the sub components of the dropdown using the method described here. The sub components can be imported via
1import { StyledDropdownComponents } from 'react-dropdown-aria';
Each component is a property on that import and has the same keys as those listed above using typical component casing. (Example)
Property | Type | Default | Description |
---|---|---|---|
ariaDescribedBy | string | null | ID of element that should be used to describe the dropdown |
ariaLabel | string | null | Aria Label to be applied to the main dropdown button |
ariaLabelledBy | string | null | ID of element that should be used as the label for the dropdown |
arrowRenderer | function | undefined | Custom function to render the arrow for the dropdown |
centerText | boolean | false | Whether main dropdown button text should be centered or not |
className | string | undefined | CSS class to be applied to the drodown |
contentClassName | string | undefined | CSS class to be applied to the dropdown option ul container |
defaultOpen | boolean | false | Whether the dropdown should be open by default |
disabled | boolean | false | Whether the dropdown should be disabled or not |
height | number | null | Use to set the dropdown height manually |
hideArrow | boolean | false | Controls whether dropdown component has the arrow or not |
id | string | undefined | id to be passed to the main dropdown button |
maxContentHeight | number | null | Controls the max height of the dropdown area that contains all options |
onChange | function | undefined | Function called when the selected value changes |
openUp | boolean | false | Whether dropdown should open up or not |
optionRenderer | function | undefined | Custom function to render the options displayed in the dropdown |
options | array | [] | Array of option objects |
optionClassName | string | undefined | CSS class to be applied to all options in the dropdown |
pageKeyTraverseSize | number | 10 | Number of options page up or page down will move the current focused by |
placeholder | string | Select... | Placeholder value for dropdown |
value | string | null | The value of the option that is currently selected (as set by setSelected ). |
selectedValueClassName | string | undefined | CSS class to be applied to main drodown button text |
searchable | boolean | true | Whether or not the keyboard can be used to quickly navigate to an item through typing |
theme | RdaTheme | undefined | Use to change the style of the dropdown through js instead of css (see styling section) |
width | number | null | Use to set the dropdown width manually |
Clone the repo
git clone https://github.com/jfangrad/react-dropdown-aria.git
Install node modules
yarn install
Then in two seperate consoles start the library and demo
yarn lib:dev
yarn demo:start
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/8 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
99 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More