Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MDCMenu.prototype.initialSyncWithDOM = function () {
var _this = this;
this.menuSurface_ = this.menuSurfaceFactory_(this.root_);
var list = this.root_.querySelector(strings.LIST_SELECTOR);
if (list) {
this.list_ = this.listFactory_(list);
this.list_.wrapFocus = true;
}
else {
this.list_ = null;
}
this.handleKeydown_ = function (evt) { return _this.foundation_.handleKeydown(evt); };
this.handleItemAction_ = function (evt) { return _this.foundation_.handleItemAction(_this.items[evt.detail.index]); };
this.handleMenuSurfaceOpened_ = function () { return _this.foundation_.handleMenuSurfaceOpened(); };
this.menuSurface_.listen(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.handleMenuSurfaceOpened_);
this.listen('keydown', this.handleKeydown_);
this.listen(MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction_);
};
MDCMenu.prototype.destroy = function () {
initialSyncWithDOM() {
this.afterOpenedCallback_ = () => this.handleAfterOpened_();
this.handleKeydown_ = (evt) => this.foundation_.handleKeydown(evt);
this.handleClick_ = (evt) => this.foundation_.handleClick(evt);
this.menuSurface_.listen(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.afterOpenedCallback_);
this.listen('keydown', this.handleKeydown_);
this.listen('click', this.handleClick_);
}
open_ = (): void => {
if (this.props.open) {
if (!this.menuSurfaceElement.current) return;
const focusableElements = this.menuSurfaceElement.current.querySelectorAll(
MDCMenuSurfaceFoundation.strings.FOCUSABLE_ELEMENTS
);
this.firstFocusableElement =
focusableElements.length > 0 ? focusableElements[0] as HTMLElement : null;
this.lastFocusableElement =
focusableElements.length > 0
? focusableElements[focusableElements.length - 1] as HTMLElement
: null;
this.foundation.open();
} else {
this.foundation.close();
}
};