@carbon/react
Version:
React components for the Carbon Design System
65 lines (57 loc) • 2.19 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var PropTypes = require('prop-types');
var usePrefix = require('../../internal/usePrefix.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
/**
* `ListBoxField` is responsible for creating the containing node for valid
* elements inside of a field. It also provides a11y-related attributes like
* `role` to make sure a user can focus the given field.
*/
function ListBoxField({
children,
disabled,
tabIndex,
...rest
}) {
const prefix = usePrefix.usePrefix();
return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
className: `${prefix}--list-box__field`,
tabIndex: !disabled && tabIndex || -1
}, rest), children);
}
ListBoxField.propTypes = {
/**
* Typically set by `getToggleButtonProps`, this should specify whether the
* field has a popup.
*/
'aria-haspopup': PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].bool]),
/**
* Provide the contents of your ListBoxField
*/
children: PropTypes__default["default"].node,
/**
* Specify if the parent <ListBox> is disabled
*/
disabled: PropTypes__default["default"].bool,
/**
* The role for the component, should be set by `getToggleButtonProps` coming
* from Downshift
*/
role: PropTypes__default["default"].string,
/**
* Optional prop to specify the tabIndex of the <ListBox> trigger button
*/
tabIndex: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].string])
};
exports["default"] = ListBoxField;