Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set open(value) {
if (value && this.foundation && !this.foundation.isOpen()) {
const focusableElements = this.root.ref
? this.root.ref.querySelectorAll(
MDCMenuSurfaceFoundation.strings.FOCUSABLE_ELEMENTS
)
: [];
this.firstFocusableElement =
focusableElements.length > 0 ? focusableElements[0] : null;
this.lastFocusableElement =
focusableElements.length > 0
? focusableElements[focusableElements.length - 1]
: null;
this.foundation.open();
} else {
if (this.foundation && this.foundation.isOpen()) {
this.foundation.close();
}
}
}
useEffect(() => {
const value = open;
if (value) {
const focusableElements = rootEl.ref
? rootEl.ref.querySelectorAll(
MDCMenuSurfaceFoundation.strings.FOCUSABLE_ELEMENTS
)
: [];
firstFocusableElementRef.current =
focusableElements.length > 0 ? focusableElements[0] : null;
foundation.open();
} else if (foundation.isOpen()) {
foundation.close();
}
}, [open, foundation, rootEl.ref]);
open_ = () => {
if (this.props.open) {
const focusableElements
= this.menuSurfaceElement_.current.querySelectorAll(MDCMenuSurfaceFoundation.strings.FOCUSABLE_ELEMENTS);
this.firstFocusableElement_ = focusableElements.length > 0 ? focusableElements[0] : null;
this.lastFocusableElement_ = focusableElements.length > 0 ?
focusableElements[focusableElements.length - 1] : null;
this.foundation_.open();
} else {
this.foundation_.close();
}
}