UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

60 lines (59 loc) 2.34 kB
import { compareItemEquality } from "../internals/itemEquality.mjs"; import { hasNullItemLabel, stringifyAsValue } from "../internals/resolveValueLabel.mjs"; export const selectors = { id: state => state.id, labelId: state => state.labelId, modal: state => state.modal, items: state => state.items, itemToStringLabel: state => state.itemToStringLabel, isItemEqualToValue: state => state.isItemEqualToValue, value: state => state.value, hasSelectedValue: state => { const { value, multiple, itemToStringValue } = state; if (value == null) { return false; } if (multiple && Array.isArray(value)) { return value.length > 0; } return stringifyAsValue(value, itemToStringValue) !== ''; }, hasNullItemLabel: (state, enabled) => { return enabled ? hasNullItemLabel(state.items) : false; }, open: state => state.open, mounted: state => state.mounted, forceMount: state => state.forceMount, transitionStatus: state => state.transitionStatus, openMethod: state => state.openMethod, activeIndex: state => state.activeIndex, selectedIndex: state => state.selectedIndex, isActive: (state, index) => state.activeIndex === index, isSelected: (state, itemValue) => { const comparer = state.isItemEqualToValue; const storeValue = state.value; if (state.multiple) { return Array.isArray(storeValue) && storeValue.some(selectedItem => compareItemEquality(itemValue, selectedItem, comparer)); } // The value is the source of truth: a stale `selectedIndex` (e.g. the controlled // value changes while the popup is open, where the index sync is deferred) must not // keep a previously selected item marked as selected. return compareItemEquality(itemValue, storeValue, comparer); }, isSelectedByFocus: (state, index) => { return state.selectedIndex === index; }, popupProps: state => state.popupProps, triggerProps: state => state.triggerProps, triggerElement: state => state.triggerElement, positionerElement: state => state.positionerElement, listElement: state => state.listElement, popupSide: state => state.popupSide, scrollUpArrowVisible: state => state.scrollUpArrowVisible, scrollDownArrowVisible: state => state.scrollDownArrowVisible, hasScrollArrows: state => state.hasScrollArrows };