Skip to content

Conversation

@chang47
Copy link
Contributor

@chang47 chang47 commented May 7, 2018

Problem:
In Chrome, if we were to press enter in a button in a contextual menu we will incorrectly put focus on the body of the page.

The reason is, because when we close the menu in chrome, we would call the onBlur in the Popup component inside the ContextualMenu, we would incorrectly set our containsFocus to be false, as a result when we run unmount, we won't put focus back to the previous element.

Solution:
We can detect in our event to see if we hit this scenario described above, by looking at the relatedTarget (the element that will gain focus), if it's null, we know that either the type is not supported (not in the case of buttons) or that it doesn't exist, which means we're closing the menu and should not set containFocus to be false.

Validation:

  • Pressing enter in a contextual menu will no longer make us lose focus on the base button.
  • Other behaviors like esc and clicking after keyboarding to open the menu remains the same.

@chang47 chang47 requested a review from jspurlin May 7, 2018 23:17
@chang47 chang47 merged commit c6b7589 into microsoft:master May 8, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request May 13, 2018
* master: (52 commits)
  Marqueeselection style update (microsoft#4803)
  Applying package updates.
  FocusZone: Add the ability to stop focus from propagating outside the FocusZone (microsoft#4823)
  Unknown persona coin (microsoft#4809)
  Applying package updates.
  BaseButton: Allow Alt + Down on menu buttons to open the menu (microsoft#4807)
  Applying package updates.
  Website: Scroll to top of page on navigation (microsoft#4810)
  Applying package updates.
  ActivityItem: fix getstyles (microsoft#4802)
  Mark Slider#ValuePosition enum as deprecated as it is unused. (microsoft#4799)
  Icon: ensure `styles` still works. (microsoft#4805)
  Popup: Added check for onBlur to prevent focus setting focus to be incorrectly disabled when closing a menu in Chrome (microsoft#4804)
  Update package.json
  Move <Layer> to use React portals when available (microsoft#4724)
  Fix breadcrumb rendering issue when overflow item is at last index  (microsoft#4787)
  Fixes focus issue for contextual menus (microsoft#4744)
  Remove redundant selected items prop on BaseExtendedPicker (microsoft#4769)
  SearchBox: New prop for turning off icon animation (microsoft#4794)
  Add functions to ContextualMenuItem to open and close menus on command (microsoft#4741)
  ...
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants