src/OverlayMixin.js
function openedChanged(element) {
  if (element.state.autoFocus) {
    if (element.state.opened) {
      // Opened
      if (!element[restoreFocusToElementKey] && document.activeElement !== document.body) {
        // Remember which element had the focus before we were opened.
        element[restoreFocusToElementKey] = document.activeElement;
      }
      // Focus on the element itself (if it's focusable), or the first focusable
      // element inside it.
      // TODO: We'd prefer to require that overlays (like the Overlay base
      // class) make use of delegatesFocus via DelegateFocusMixin, which would
      // let us drop the need for this mixin here to do anything special with
      // focus. However, an initial trial of this revealed an issue in
      // MenuButton, where invoking the menu did not put the focus on the first
      // menu item as expected. Needs more investigation.
      const focusElement = firstFocusableElement(element);
      if (focusElement) {
        focusElement.focus();
      }
    } else {
      // Closed
      if (element[restoreFocusToElementKey]) {
        // Restore focus to the element that had the focus before the overlay was
        // opened.
        element[restoreFocusToElementKey].focus();
        element[restoreFocusToElementKey] = null;
      }
    }
  }
}
function openedChanged(element) {
  if (element.state.autoFocus) {
    if (element.state.opened) {
      // Opened
      if (!element[restoreFocusToElementKey] && document.activeElement !== document.body) {
        // Remember which element had the focus before we were opened.
        element[restoreFocusToElementKey] = document.activeElement;
      }
      // Focus on the element itself (if it's focusable), or the first focusable
      // element inside it.
      // TODO: We'd prefer to require that overlays (like the Overlay base
      // class) make use of delegatesFocus via DelegateFocusMixin, which would
      // let us drop the need for this mixin here to do anything special with
      // focus. However, an initial trial of this revealed an issue in
      // MenuButton, where invoking the menu did not put the focus on the first
      // menu item as expected. Needs more investigation.
      const focusElement = firstFocusableElement(element);
      if (focusElement) {
        focusElement.focus();
      }
    } else {
      // Closed
      if (element[restoreFocusToElementKey]) {
        // Restore focus to the element that had the focus before the overlay was
        // opened.
        element[restoreFocusToElementKey].focus();
        element[restoreFocusToElementKey] = null;
      }
    }
  }
}
function openedChanged ( element ) { if ( element . state . autoFocus ) { if ( element . state . opened ) { // Opened if ( ! element [ restoreFocusToElementKey ] && document . activeElement !== document . body ) { // Remember which element had the focus before we were opened. element [ restoreFocusToElementKey ] = document . activeElement ; } // Focus on the element itself (if it's focusable), or the first focusable // element inside it. // TODO: We'd prefer to require that overlays (like the Overlay base // class) make use of delegatesFocus via DelegateFocusMixin, which would // let us drop the need for this mixin here to do anything special with // focus. However, an initial trial of this revealed an issue in // MenuButton, where invoking the menu did not put the focus on the first // menu item as expected. Needs more investigation. const focusElement = firstFocusableElement ( element ) ; if ( focusElement ) { focusElement . focus ( ) ; } } else { // Closed if ( element [ restoreFocusToElementKey ] ) { // Restore focus to the element that had the focus before the overlay was // opened. element [ restoreFocusToElementKey ] . focus ( ) ; element [ restoreFocusToElementKey ] = null ; } } } }
Update the overlay following a change in opened state.
Update the overlay following a change in opened state .