Skip to content

FocusUtil: fix getPreviousElement to include previous sibling elements correctly#3928

Merged
dzearing merged 6 commits intomicrosoft:masterfrom
jspurlin:jspurlin/FocusFixFindPrevElement
Feb 16, 2018
Merged

FocusUtil: fix getPreviousElement to include previous sibling elements correctly#3928
dzearing merged 6 commits intomicrosoft:masterfrom
jspurlin:jspurlin/FocusFixFindPrevElement

Conversation

@jspurlin
Copy link
Copy Markdown
Contributor

@jspurlin jspurlin commented Feb 8, 2018

Pull request checklist

  • Include a change request file using $ npm run change

Description of changes

The getPreviousElement functionality missed elements if a potential childMatch was found, but it was not tabbable (or tabbable is false) and the elemeent that should be found is a previous sibiling of childMatch.

Here;s some example:
This worked:
<Focus starts before the zone, and is being put into the focusZone via the logic in FocusTrapZone>
FocusZone
OverflowSetItem
button (tabindex=0)
OverflowSetItem
button (tabindex=-1)
OverflowSetItem
button (tabindex=-1)
It goes down to the last button. The currentElement is on the last OverflowSetItem and it finds the button when looking for childMatch. From there determines it is not focusable (because of the isElementTabbable(childMatch, true /checkTabIndex/) call) so it would go to currentElement's previousSibling to continue looking (until it gets to the first button and then it finds athat as a match).

This did not work:
<Focus starts before the zone, and is being put into the focusZone via the logic in FocusTrapZone>
FocusZone
OverflowSetItem
button (tabindex=0)
button (tabindex=-1)
button (tabindex=-1)

It goes down to the last button. The currentElement is on the last OverflowSetItem and it finds the button when looking for childMatch. From there determines it is not focusable (because of the isElementTabbable(childMatch, true /checkTabIndex/) call) so it would go to currentElement's previousSibling to continue looking. Note that this skips all the other sibling buttons.

This fix is when we find a potential childMatch which we determine we cannot focus, move to that element's previous child instead of moving on to the next sibling of the parent (currentElement)

Focus areas to test

Verified that focus correctly moves to the previous element in all tested cases (including the two above)


if (childMatch && ((tabbable && (isElementTabbable(childMatch, true))) || !tabbable)) {
return childMatch;
if (childMatch) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to write a unit test for this scenario?

Also, is there logic missing on "findNextElement"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNextElement doesn't need to be updated, the logic is slightly different and doesn't check for tabindex when checking if an element is tabbable. There may be some other bug hidden in here from that difference, but it doesn't need this update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yes, I'll look at adding a unit test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool ping me once you have a test to cover it (so we don't break it later!) and let's get it merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzearing done, ut added. I also verified that this breaks without my fix and works with it :)

@dzearing dzearing merged commit f0c4c5c into microsoft:master Feb 16, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Feb 18, 2018
* master: (71 commits)
  Applying package updates.
  Delete initials_2018-02-07-13-49.json
  Delete initials_2018-02-07-13-49.json
  Delete jolore-addingWorkWeekDateRange_2018-01-24-01-39.json
  Delete initials_2018-02-07-13-49.json
  Delete jolore-addingWorkWeekDateRange_2018-01-24-01-39.json
  Delete initials_2018-02-07-13-49.json
  Update .npmrc
  Cleaning Up Console Log in CommandBar Test (microsoft#4011)
  Convert Overlay to mergeStyles (microsoft#3978)
  ScrollablePane SCSS to MergeStyles Part 1: File Structure (microsoft#4008)
  [ContextualMenu] Fixes useTargetWidth property (microsoft#3943)
  DetailsList: Consider groups when setting aria-rowcount
  List: Add a _notifyPageChanges function  (microsoft#3990)
  Applying package updates.
  Migrating Coachmark to main Package, Added a beak component and updated experiment PositioningContainer. (microsoft#3919)
  Update package.json
  Added enum for triggering menu with arrow keys and bool to allow it or not (microsoft#3950)
  BaseExtendedPicker: Hook up onPaste (microsoft#3885)
  FocusUtil: fix getPreviousElement to include previous sibling elements correctly (microsoft#3928)
  ...
@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.

3 participants