function onKeyDown(e) {
    if (e.key !== 'Tab' && (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)) {
      return;
    }

    if (isValidFocusTarget(document.activeElement)) {
      addFocusVisibleAttribute(document.activeElement);
    }

    hadKeyboardEvent = true;
  }
Treat `keydown` as a signal that the user is in keyboard modality.
Apply `focus-visible` to any current active element and keep track
of our keyboard modality state with `hadKeyboardEvent`.