Gathering detailed insights and metrics for use-item-list
Gathering detailed insights and metrics for use-item-list
Gathering detailed insights and metrics for use-item-list
Gathering detailed insights and metrics for use-item-list
@csstools/postcss-normalize-display-values
Use two values display syntax for inner and outer display types.
@yozora/tokenizer-list-item
<!-- :begin use tokenizer/banner -->
react-native-item-list
The React Native ListItem package is a versatile, easy-to-use solution for creating interactive item lists in your React Native applications. Designed to simplify the process of creating and displaying item lists, this package offers maximum flexibility w
5app-use-item-list
Manage indexed collections in React using hooks.
A primitive React hook used to coordinate indexed collections effortlessly.
npm install use-item-list
Typescript
Module System
JavaScript (66.25%)
TypeScript (30.99%)
CSS (2.69%)
Shell (0.06%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
74 Stars
21 Commits
5 Forks
4 Watchers
18 Branches
2 Contributors
Updated on Mar 07, 2024
Latest Version
0.1.2
Package Id
use-item-list@0.1.2
Unpacked Size
104.47 kB
Size
23.59 kB
File Count
13
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
A primitive React hook used to coordinate indexed collections effortlessly.
The ergonmics of managing indexes in React is lacking. When building lower level components for accessibility purposes, managing indexes can become painful and expose internals of an API that consumers shouldn't necessarily need to know about.
This library aims to solve managing indexed collections of items as easily as possible while letting users still compose, optimize, and use React like they are used to.
1import React, { useRef } from 'react'
2import { useItemList } from 'use-item-list'
3
4function Item({ useItem, children }) {
5 const ref = useRef()
6 const { id, index, highlight, select, selected, useHighlighted } = useItem({
7 ref, // required ref used to scroll item into view when highlighted
8 value: children, // value passed back in useItemList onSelect
9 disabled: false, // prevents item from being highlighted/selected
10 text: null, // used for highlightItemByString function
11 })
12 return (
13 <li ref={ref} id={id}>
14 {children}
15 </li>
16 )
17}
18
19function List({ value, onChange }) {
20 const {
21 controllerId,
22 listId,
23 getHighlightedIndex,
24 getHighlightedItem,
25 setHighlightedItem,
26 moveHighlightedItem,
27 clearHighlightedItem,
28 selectHighlightedItem,
29 useHighlightedItemId,
30 highlightItemByString,
31 useItem,
32 } = useItemList({
33 selected: value, // the current selected value
34 onSelect: onChange, // callback when item has been selected
35 })
36 return (
37 <ul>
38 <Item useItem={useItem}>Item 1</Item>
39 <Item useItem={useItem}>Item 2</Item>
40 <Item useItem={useItem}>Item 3</Item>
41 </ul>
42 )
43}
In a somewhat trivial example, we can see how to build a custom select menu:
1import React, { createContext, useContext, useRef } from 'react' 2import { useItemList } from 'use-item-list' 3 4const SelectContext = createContext() 5 6export function Select({ children, value, onChange }) { 7 const itemList = useItemList({ 8 selected: value, 9 onSelect: onChange, 10 }) 11 const itemId = itemList.useHighlightedItemId() 12 return ( 13 <SelectContext.Provider value={itemList}> 14 <ul 15 id={itemList.listId} 16 tabIndex={0} 17 role="listbox" 18 aria-activedescendant={itemId} 19 style={{ padding: 0 }} 20 onKeyDown={(event) => { 21 if (event.key === 'ArrowUp') { 22 event.preventDefault() 23 itemList.moveHighlightedItem(-1) 24 } 25 if (event.key === 'ArrowDown') { 26 event.preventDefault() 27 itemList.moveHighlightedItem(1) 28 } 29 if (event.key === ' ' || event.key === 'Enter') { 30 event.preventDefault() 31 itemList.selectHighlightedItem() 32 } 33 itemList.highlightItemByString(event) 34 }} 35 > 36 {children} 37 </ul> 38 </SelectContext.Provider> 39 ) 40} 41 42export function Option({ children, text, value }) { 43 const { useItem, clearHighlightedItem } = useContext(SelectContext) 44 const ref = useRef() 45 const { id, highlight, select, selected, useHighlighted } = useItem({ 46 ref, 47 text, 48 value, 49 }) 50 const highlighted = useHighlighted() 51 return ( 52 <li 53 ref={ref} 54 id={id} 55 role="option" 56 aria-selected={selected} 57 onMouseOver={highlight} 58 onMouseOut={clearHighlightedItem} 59 onMouseDown={select} 60 > 61 {children} {selected && '✅'} 62 </li> 63 ) 64}
Now users of our component have an easy-to-use API that resembles the ergonomics of the web's select element:
1<Select> 2 <Option value="apple">Apple 🍎</Option> 3 <Option value="banana">Banana 🍌</Option> 4 <Option value="pear">Pear 🍐</Option> 5</Select>
Please note this is not a fully accessible example. See the examples directory for more full-fledged examples.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 1/19 approved changesets -- score normalized to 0
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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
102 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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