Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Accordion = React.forwardRef((props, ref) => {
let {
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
activeKey,
bsPrefix,
children,
className,
onSelect,
...controlledProps
} = useUncontrolled(props, {
activeKey: 'onSelect',
});
bsPrefix = useBootstrapPrefix(bsPrefix, 'accordion');
return (
{children}
inputPlaceholder,
isDisabled,
isMultiselect,
isReadOnly,
isSearchable,
onBlur,
onChange,
onChangeInput,
onClick,
onFocus,
options: rawOptions,
popperContainer,
style,
value: rawValue,
...restProps
} = useUncontrolled(props, { value: "onChange" });
// normalize the options passed as prop
const options = useMemo(
() =>
Array.isArray(rawOptions)
? rawOptions.map(opt =>
typeof opt === "object"
? opt
: { id: String(opt), text: String(opt) }
)
: [],
[rawOptions]
);
// flat array of all options
const flatOptions = useMemo(
function Dropdown({
drop,
alignEnd,
defaultShow,
show: rawShow,
onToggle: rawOnToggle,
itemSelector,
focusFirstItemOnShow,
children,
}) {
const forceUpdate = useForceUpdate();
const { show, onToggle } = useUncontrolled(
{ defaultShow, show: rawShow, onToggle: rawOnToggle },
{ show: 'onToggle' },
);
const [toggleElement, setToggle] = useCallbackRef();
// We use normal refs instead of useCallbackRef in order to populate the
// the value as quickly as possible, otherwise the effect to focus the element
// may run before the state value is set
const menuRef = useRef();
const menuElement = menuRef.current;
const setMenu = useCallback(
ref => {
menuRef.current = ref;
// ensure that a menu set triggers an update for consumers