@carbon/react
Version:
React components for the Carbon Design System
60 lines (54 loc) • 1.73 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.
*/
'use strict';
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');
/**
* `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.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.oneOfType([PropTypes.string, PropTypes.bool]),
/**
* Provide the contents of your ListBoxField
*/
children: PropTypes.node,
/**
* Specify if the parent <ListBox> is disabled
*/
disabled: PropTypes.bool,
/**
* The role for the component, should be set by `getToggleButtonProps` coming
* from Downshift
*/
role: PropTypes.string,
/**
* Optional prop to specify the tabIndex of the <ListBox> trigger button
*/
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
};
exports.default = ListBoxField;