Socket
Socket
Sign inDemoInstall

@react-aria/listbox

Package Overview
Dependencies
Maintainers
1
Versions
732
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/listbox - npm Package Compare versions

Comparing version 3.0.0-alpha.1 to 3.0.0-rc.0

dist/main.js.map

160

dist/main.js

@@ -1,18 +0,25 @@

var _babelRuntimeHelpersObjectSpread = $parcel$interopDefault(require("@babel/runtime/helpers/objectSpread2"));
var {
isFocusVisible,
useHover,
usePress
} = require("@react-aria/interactions");
var _temp = require("@react-aria/selection");
var {
useSelectableList,
useSelectableItem
} = require("@react-aria/selection");
var useSelectableList = _temp.useSelectableList;
var useSelectableItem = _temp.useSelectableItem;
var {
useLabel
} = require("@react-aria/label");
var _temp2 = require("@react-aria/interactions");
var {
filterDOMProps,
mergeProps,
useSlotId,
useId
} = require("@react-aria/utils");
var useHover = _temp2.useHover;
var usePress = _temp2.usePress;
var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
var _temp3 = require("@react-aria/utils");
var useSlotId = _temp3.useSlotId;
var useId = _temp3.useId;
function $parcel$interopDefault(a) {

@@ -22,14 +29,34 @@ return a && a.__esModule ? a.default : a;

function useListBox(props, state) {
var _useSelectableList = useSelectableList(_babelRuntimeHelpersObjectSpread({}, props, {
/**
* Provides the behavior and accessibility implementation for a listbox component.
* A listbox displays a list of options and allows a user to select one or more of them.
* @param props - props for the listbox
* @param state - state for the listbox, as returned by `useListState`
*/
function useListBox(props, state, ref) {
let domProps = filterDOMProps(props, {
labelable: true
});
let {
listProps
} = useSelectableList(_babelRuntimeHelpersExtends({}, props, {
ref,
selectionManager: state.selectionManager,
collection: state.collection
})),
listProps = _useSelectableList.listProps;
collection: state.collection,
disabledKeys: state.disabledKeys
}));
let {
labelProps,
fieldProps
} = useLabel(_babelRuntimeHelpersExtends({}, props, {
// listbox is not an HTML input element so it
// shouldn't be labeled by a <label> element.
labelElementType: 'span'
}));
return {
listBoxProps: _babelRuntimeHelpersObjectSpread({
labelProps,
listBoxProps: mergeProps(domProps, _babelRuntimeHelpersExtends({
role: 'listbox',
'aria-multiselectable': state.selectionManager.selectionMode === 'multiple' ? 'true' : undefined
}, listProps)
}, mergeProps(fieldProps, listProps)))
};

@@ -40,13 +67,20 @@ }

function useOption(props, state) {
var isSelected = props.isSelected,
isDisabled = props.isDisabled,
key = props.key,
ref = props.ref,
shouldSelectOnPressUp = props.shouldSelectOnPressUp,
shouldFocusOnHover = props.shouldFocusOnHover,
isVirtualized = props.isVirtualized;
var labelId = useSlotId();
var descriptionId = useSlotId();
var optionProps = {
/**
* Provides the behavior and accessibility implementation for an option in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the option
* @param state - state for the listbox, as returned by `useListState`
*/
function useOption(props, state, ref) {
let {
isSelected,
isDisabled,
key,
shouldSelectOnPressUp,
shouldFocusOnHover,
isVirtualized
} = props;
let labelId = useSlotId();
let descriptionId = useSlotId();
let optionProps = {
role: 'option',

@@ -61,30 +95,35 @@ 'aria-disabled': isDisabled,

if (isVirtualized) {
optionProps['aria-posinset'] = state.collection.getItem(key).index;
optionProps['aria-posinset'] = state.collection.getItem(key).index + 1;
optionProps['aria-setsize'] = state.collection.size;
}
var _useSelectableItem = useSelectableItem({
let {
itemProps
} = useSelectableItem({
selectionManager: state.selectionManager,
itemKey: key,
itemRef: ref,
shouldSelectOnPressUp: shouldSelectOnPressUp,
isVirtualized: isVirtualized
}),
itemProps = _useSelectableItem.itemProps;
key,
ref,
shouldSelectOnPressUp,
isVirtualized
});
let {
pressProps
} = usePress(_babelRuntimeHelpersExtends({}, itemProps, {
isDisabled
}));
let {
hoverProps
} = useHover({
isDisabled: isDisabled || !shouldFocusOnHover,
var _usePress = usePress(_babelRuntimeHelpersObjectSpread({}, itemProps, {
isDisabled: isDisabled
})),
pressProps = _usePress.pressProps;
var _useHover = useHover({
isDisabled: isDisabled || !shouldFocusOnHover,
onHover: function onHover() {
state.selectionManager.setFocusedKey(key);
onHoverStart() {
if (!isFocusVisible()) {
state.selectionManager.setFocused(true);
state.selectionManager.setFocusedKey(key);
}
}
}),
hoverProps = _useHover.hoverProps;
});
return {
optionProps: _babelRuntimeHelpersObjectSpread({}, optionProps, {}, pressProps, {}, hoverProps),
optionProps: _babelRuntimeHelpersExtends({}, optionProps, {}, mergeProps(pressProps, hoverProps)),
labelProps: {

@@ -101,7 +140,17 @@ id: labelId

/**
* Provides the behavior and accessibility implementation for a section in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the section
*/
function useListBoxSection(props) {
var heading = props.heading,
ariaLabel = props['aria-label'];
var headingId = useId();
let {
heading,
'aria-label': ariaLabel
} = props;
let headingId = useId();
return {
itemProps: {
role: 'presentation'
},
headingProps: heading ? {

@@ -122,2 +171,3 @@ // Techincally, listbox cannot contain headings according to ARIA.

exports.useListBoxSection = useListBoxSection;
exports.useListBoxSection = useListBoxSection;
//# sourceMappingURL=main.js.map

@@ -1,20 +0,49 @@

import _babelRuntimeHelpersEsmObjectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { isFocusVisible, useHover, usePress } from "@react-aria/interactions";
import { useSelectableList, useSelectableItem } from "@react-aria/selection";
import { useHover, usePress } from "@react-aria/interactions";
import { useSlotId, useId } from "@react-aria/utils";
export function useListBox(props, state) {
import { useLabel } from "@react-aria/label";
import { filterDOMProps, mergeProps, useSlotId, useId } from "@react-aria/utils";
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
/**
* Provides the behavior and accessibility implementation for a listbox component.
* A listbox displays a list of options and allows a user to select one or more of them.
* @param props - props for the listbox
* @param state - state for the listbox, as returned by `useListState`
*/
export function useListBox(props, state, ref) {
let domProps = filterDOMProps(props, {
labelable: true
});
let {
listProps
} = useSelectableList(_babelRuntimeHelpersEsmObjectSpread({}, props, {
} = useSelectableList(_babelRuntimeHelpersEsmExtends({}, props, {
ref,
selectionManager: state.selectionManager,
collection: state.collection
collection: state.collection,
disabledKeys: state.disabledKeys
}));
let {
labelProps,
fieldProps
} = useLabel(_babelRuntimeHelpersEsmExtends({}, props, {
// listbox is not an HTML input element so it
// shouldn't be labeled by a <label> element.
labelElementType: 'span'
}));
return {
listBoxProps: _babelRuntimeHelpersEsmObjectSpread({
labelProps,
listBoxProps: mergeProps(domProps, _babelRuntimeHelpersEsmExtends({
role: 'listbox',
'aria-multiselectable': state.selectionManager.selectionMode === 'multiple' ? 'true' : undefined
}, listProps)
}, mergeProps(fieldProps, listProps)))
};
}
export function useOption(props, state) {
/**
* Provides the behavior and accessibility implementation for an option in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the option
* @param state - state for the listbox, as returned by `useListState`
*/
export function useOption(props, state, ref) {
let {

@@ -24,3 +53,2 @@ isSelected,

key,
ref,
shouldSelectOnPressUp,

@@ -42,3 +70,3 @@ shouldFocusOnHover,

if (isVirtualized) {
optionProps['aria-posinset'] = state.collection.getItem(key).index;
optionProps['aria-posinset'] = state.collection.getItem(key).index + 1;
optionProps['aria-setsize'] = state.collection.size;

@@ -51,4 +79,4 @@ }

selectionManager: state.selectionManager,
itemKey: key,
itemRef: ref,
key,
ref,
shouldSelectOnPressUp,

@@ -59,3 +87,3 @@ isVirtualized

pressProps
} = usePress(_babelRuntimeHelpersEsmObjectSpread({}, itemProps, {
} = usePress(_babelRuntimeHelpersEsmExtends({}, itemProps, {
isDisabled

@@ -68,4 +96,7 @@ }));

onHover() {
state.selectionManager.setFocusedKey(key);
onHoverStart() {
if (!isFocusVisible()) {
state.selectionManager.setFocused(true);
state.selectionManager.setFocusedKey(key);
}
}

@@ -75,3 +106,3 @@

return {
optionProps: _babelRuntimeHelpersEsmObjectSpread({}, optionProps, {}, pressProps, {}, hoverProps),
optionProps: _babelRuntimeHelpersEsmExtends({}, optionProps, {}, mergeProps(pressProps, hoverProps)),
labelProps: {

@@ -85,2 +116,8 @@ id: labelId

}
/**
* Provides the behavior and accessibility implementation for a section in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the section
*/
export function useListBoxSection(props) {

@@ -93,2 +130,5 @@ let {

return {
itemProps: {
role: 'presentation'
},
headingProps: heading ? {

@@ -107,2 +147,3 @@ // Techincally, listbox cannot contain headings according to ARIA.

};
}
}
//# sourceMappingURL=module.js.map

@@ -1,42 +0,83 @@

import { FocusStrategy } from "@react-types/listbox";
import { HTMLAttributes, RefObject, Key, ReactNode } from "react";
import { AriaListBoxProps } from "@react-types/listbox";
import { HTMLAttributes, ReactNode, RefObject, Key } from "react";
import { KeyboardDelegate } from "@react-types/shared";
import { ListState } from "@react-stately/list";
interface ListBoxAria {
/** Props for the listbox element. */
listBoxProps: HTMLAttributes<HTMLElement>;
/** Props for the listbox's visual label element (if any). */
labelProps: HTMLAttributes<HTMLElement>;
}
interface AriaListBoxProps {
ref?: RefObject<HTMLDivElement>;
interface AriaListBoxOptions<T> extends AriaListBoxProps<T> {
/** Whether the listbox uses virtual scrolling. */
isVirtualized?: boolean;
/**
* An optional keyboard delegate implementation for type to select,
* to override the default.
*/
keyboardDelegate?: KeyboardDelegate;
autoFocus?: boolean | FocusStrategy;
shouldFocusWrap?: boolean;
/**
* An optional visual label for the listbox.
*/
label?: ReactNode;
}
export function useListBox<T>(props: AriaListBoxProps, state: ListState<T>): ListBoxAria;
interface OptionProps {
/**
* Provides the behavior and accessibility implementation for a listbox component.
* A listbox displays a list of options and allows a user to select one or more of them.
* @param props - props for the listbox
* @param state - state for the listbox, as returned by `useListState`
*/
export function useListBox<T>(props: AriaListBoxOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement>): ListBoxAria;
interface OptionAria {
/** Props for the option element. */
optionProps: HTMLAttributes<HTMLElement>;
/** Props for the main text element inside the option. */
labelProps: HTMLAttributes<HTMLElement>;
/** Props for the description text element inside the option, if any. */
descriptionProps: HTMLAttributes<HTMLElement>;
}
interface AriaOptionProps {
/** Whether the option is disabled. */
isDisabled?: boolean;
/** Whether the option is selected. */
isSelected?: boolean;
/** A screen reader only label for the option. */
'aria-label'?: string;
/** The unique key for the option. */
key?: Key;
ref?: RefObject<HTMLElement>;
/** Whether selection should occur on press up instead of press down. */
shouldSelectOnPressUp?: boolean;
/** Whether the option should be focused when the user hovers over it. */
shouldFocusOnHover?: boolean;
/** Whether the option is contained in a virtual scrolling listbox. */
isVirtualized?: boolean;
}
interface OptionAria {
optionProps: HTMLAttributes<HTMLElement>;
labelProps: HTMLAttributes<HTMLElement>;
descriptionProps: HTMLAttributes<HTMLElement>;
}
export function useOption<T>(props: OptionProps, state: ListState<T>): OptionAria;
interface ListBoxSectionProps {
/**
* Provides the behavior and accessibility implementation for an option in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the option
* @param state - state for the listbox, as returned by `useListState`
*/
export function useOption<T>(props: AriaOptionProps, state: ListState<T>, ref: RefObject<HTMLElement>): OptionAria;
interface AriaListBoxSectionProps {
/** The heading for the section. */
heading?: ReactNode;
/** An accessibility label for the section. Required if `heading` is not present. */
'aria-label'?: string;
}
interface ListBoxSectionAria {
/** Props for the wrapper list item. */
itemProps: HTMLAttributes<HTMLElement>;
/** Props for the heading element, if any. */
headingProps: HTMLAttributes<HTMLElement>;
/** Props for the group element. */
groupProps: HTMLAttributes<HTMLElement>;
}
export function useListBoxSection(props: ListBoxSectionProps): ListBoxSectionAria;
/**
* Provides the behavior and accessibility implementation for a section in a listbox.
* See `useListBox` for more details about listboxes.
* @param props - props for the section
*/
export function useListBoxSection(props: AriaListBoxSectionProps): ListBoxSectionAria;
//# sourceMappingURL=types.d.ts.map
{
"name": "@react-aria/listbox",
"version": "3.0.0-alpha.1",
"version": "3.0.0-rc.0",
"description": "Spectrum UI components in React",

@@ -20,7 +20,9 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-aria/interactions": "^3.0.0-rc.2",
"@react-aria/selection": "^3.0.0-alpha.1",
"@react-aria/utils": "^3.0.0-rc.2",
"@react-stately/list": "^3.0.0-alpha.1",
"@react-types/listbox": "^3.0.0-alpha.1"
"@react-aria/interactions": "3.0.0-rc.3",
"@react-aria/label": "3.0.0-rc.3",
"@react-aria/selection": "3.0.0-rc.0",
"@react-aria/utils": "3.0.0-rc.3",
"@react-stately/list": "3.0.0-rc.0",
"@react-types/listbox": "3.0.0-rc.0",
"@react-types/shared": "3.0.0-rc.3"
},

@@ -33,3 +35,3 @@ "peerDependencies": {

},
"gitHead": "207e6ee9076905c96638a7f81a367758872e1410"
"gitHead": "461d6321126ae9b4f1508aa912f7b36bf8a603f8"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc