@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
54 lines (50 loc) • 1.5 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { usePrefix } from '../../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(_ref) {
let {
children,
disabled,
tabIndex,
...rest
} = _ref;
const prefix = usePrefix();
return /*#__PURE__*/React__default.createElement("div", _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])
};
export { ListBoxField as default };