Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* True: Enables Filtering
* False: Disables Filtering
*/
isFilterDisabled: PropTypes.bool,
/**
* Defines the minimum height the results container will be
*/
popoverMinWidth: PropTypes.number,
/**
* Defines the maximum height the results container will be
*/
popoverMaxHeight: PropTypes.number,
...Downshift.propTypes
}
state = {
targetWidth: 0
}
static defaultProps = {
itemToString: i => (i ? String(i) : ''),
itemSize: 32,
isFilterDisabled: false,
popoverMinWidth: 240,
popoverMaxHeight: 240,
renderItem: autocompleteItemRenderer
}
componentDidMount() {
/**
* Provide the title text that will be read by a screen reader when
* visiting this control
*/
titleText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Provide helper text that is used alongside the control label for
* additional help
*/
helperText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Additional props passed to Downshift
*/
downshiftProps: PropTypes.shape(Downshift.propTypes),
};
static defaultProps = {
disabled: false,
type: 'default',
itemToString: defaultItemToString,
itemToElement: null,
light: false,
titleText: '',
helperText: '',
};
constructor(props) {
super(props);
this.dropdownInstanceId = getInstanceId();
}
* Specify feedback (mode) of the selection.
* `top`: selected item jumps to top
* `fixed`: selected item stays at it's position
* `top-after-reopen`: selected item jump to top after reopen dropdown
*/
selectionFeedback: PropTypes.oneOf(['top', 'fixed', 'top-after-reopen']),
/**
* Callback function for translating ListBoxMenuIcon SVG title
*/
translateWithId: PropTypes.func,
/**
* Additional props passed to Downshift
*/
downshiftProps: PropTypes.shape(Downshift.propTypes),
};
static getDerivedStateFromProps({ open }, state) {
/**
* programmatically control this `open` prop
*/
const { prevOpen } = state;
return prevOpen === open
? null
: {
isOpen: open,
prevOpen: open,
};
}
static defaultProps = {
/**
* Callback function to notify consumer when the text input changes.
* This provides support to change available items based on the text.
* @param {string} inputText
*/
onInputChange: PropTypes.func,
/**
* should use "light theme" (white background)?
*/
light: PropTypes.bool,
/**
* Additional props passed to Downshift
*/
downshiftProps: PropTypes.shape(Downshift.propTypes),
};
static defaultProps = {
disabled: false,
itemToString: defaultItemToString,
itemToElement: null,
shouldFilterItem: defaultShouldFilterItem,
type: 'default',
ariaLabel: 'Choose an item',
light: false,
};
constructor(props) {
super(props);
this.textInput = React.createRef();
* Callback function for translating ListBoxMenuIcon SVG title
*/
translateWithId: PropTypes.func,
/**
* Specify feedback (mode) of the selection.
* `top`: selected item jumps to top
* `fixed`: selected item stays at it's position
* `top-after-reopen`: selected item jump to top after reopen dropdown
*/
selectionFeedback: PropTypes.oneOf(['top', 'fixed', 'top-after-reopen']),
/**
* Additional props passed to Downshift
*/
downshiftProps: PropTypes.shape(Downshift.propTypes),
};
static getDerivedStateFromProps({ open }, state) {
/**
* programmatically control this `open` prop
*/
const { prevOpen } = state;
return prevOpen === open
? null
: {
isOpen: open,
prevOpen: open,
};
}
static defaultProps = {
popoverMinWidth: PropTypes.number,
/**
* Defines the maximum height the results container will be
*/
popoverMaxHeight: PropTypes.number,
/**
* The selected item to be selected & shown by default on the autocomplete (deprecated)
*/
getButtonProps: deprecated(
PropTypes.func,
'Use "getToggleButtonProps" instead.'
),
...Downshift.propTypes
}
state = {
targetWidth: 0
}
static defaultProps = {
itemToString: i => (i ? String(i) : ''),
itemSize: 32,
isFilterDisabled: false,
popoverMinWidth: 240,
popoverMaxHeight: 240,
renderItem: autocompleteItemRenderer
}
componentDidMount() {
*
* @param {Node} inputRef The input element */
setRef: PropTypes.func,
/** Optional maxLength value for the html input */
maxLength: PropTypes.number,
/** Optional specify height for the menu */
menuHeight: PropTypes.string,
/** Optional specify selectedItemValue to manage selectedItem state externally */
selectedItemValue: PropTypes.oneOfType([
PropTypes.string,
PropTypes.objectOf(PropTypes.any)
])
};
Typeahead.defaultProps = {
...Downshift.propTypes,
disabled: false,
fetchListOnInput: undefined,
id: null,
initialSelectedItem: null,
isFetchingList: false,
itemToString: item => (item ? String(item) : ''),
badgeToString: () => null,
items: [],
label: '',
onBlur: noop,
onFocus: noop,
onChange: noop,
onKeyDown: noop,
onInputValueChange: null,
setRef: noop,
message: '',
/**
* @typedef {Object} GetRemoveButtonPropsOptions
* @property {function(MouseEvent)} onClick
* @property {any} item
*/
/**
* @typedef {import("downshift").ControllerStateAndHelpers} ControllerStateAndHelpers
* @property {function(GetRemoveButtonPropsOptions): any} getRemoveButtonProps
* @property {any[]} selectedItems
*/
export default class MultiDownshift extends React.Component {
static propTypes = {
...Downshift.propTypes,
/** Controlled: the currently selected items */
selectedItems: PropTypes.arrayOf(PropTypes.any),
/** Items selected by default */
defaultSelectedItems: PropTypes.arrayOf(PropTypes.any),
/** Alias of `defaultSelectedItems` for consistency with Downshift */
initialSelectedItems: PropTypes.arrayOf(PropTypes.any)
};
static defaultProps = {
defaultSelectedItems: []
};
state = {
selectedItems: this.getDefaultSelectedItem()
};