Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FocusZone): should reset tabindex when focus is outside the zone with prop shouldResetActiveElementWhenTabFromZone #24463

Merged
merged 8 commits into from
Sep 8, 2022

Conversation

YuanboXue-Amber
Copy link
Contributor

@YuanboXue-Amber YuanboXue-Amber commented Aug 23, 2022

For a FocusZone with shouldResetActiveElementWhenTabFromZone prop specified, when it is updated before receiving focus, the zone does not update tabIndex accordingly.

In this example: https://codesandbox.io/s/fluent-ui-example-forked-hq2lzn

  • click on button to add a chat
  • tab to focus on button
  • tab again, focus should land on the last message. But it in fact land on one message above.
    This is because when one more message is added to FocusZone, the zone does not reset tabIndex, while it should

Note that initially I wanted to reset tabIndex on FocusZone re-render. But this is not enough as FocusZone's children can be updated without FocusZone itself re-render. In the end I reset tabIndex every time a keydown is captured, and focus is outside of the zone.

@YuanboXue-Amber YuanboXue-Amber changed the title fix(FocusZone): should reset tabindex on components update fix(FocusZone): should reset tabindex on component update Aug 23, 2022
@YuanboXue-Amber YuanboXue-Amber changed the title fix(FocusZone): should reset tabindex on component update fix(FocusZone): should reset tabindex when focus is outside on component update Aug 23, 2022
@YuanboXue-Amber YuanboXue-Amber changed the title fix(FocusZone): should reset tabindex when focus is outside on component update fix(FocusZone): should reset tabindex on component update when focus is outside Aug 23, 2022
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 23, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aa94848:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration
fluent-ui-example (forked) PR

@size-auditor
Copy link

size-auditor bot commented Aug 23, 2022

Asset size changes

Project Bundle Baseline Size New Size Difference
office-ui-fabric-react fluentui-react-northstar-Accordion 88.744 kB 88.853 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Input 91.402 kB 91.511 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Label 80.463 kB 80.572 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-List 91.965 kB 92.074 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Loader 81.163 kB 81.272 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Menu 132.858 kB 132.967 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-MenuButton 168.615 kB 168.724 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Pill 86.557 kB 86.666 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Popup 138.645 kB 138.754 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-RadioGroup 86.464 kB 86.573 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Reaction 79.839 kB 79.948 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Segment 78.646 kB 78.755 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Skeleton 80.12 kB 80.229 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Slider 87.408 kB 87.517 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-SplitButton 184.878 kB 184.987 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Status 78.834 kB 78.943 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Table 83.866 kB 83.975 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Text 76.417 kB 76.526 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-TextArea 76.546 kB 76.655 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Toolbar 181.13 kB 181.239 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Tooltip 112.44 kB 112.549 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Tree 91.049 kB 91.158 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Video 77.85 kB 77.959 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-ItemLayout 80.762 kB 80.871 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Layout 77.761 kB 77.87 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Image 75.819 kB 75.928 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Datepicker 193.843 kB 193.952 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Alert 90.726 kB 90.835 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Attachment 89.969 kB 90.078 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Avatar 82.971 kB 83.08 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Box 77.625 kB 77.734 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Breadcrumb 82.623 kB 82.732 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Button 86.016 kB 86.125 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Card 85.589 kB 85.698 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Carousel 109.76 kB 109.869 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Header 77.11 kB 77.219 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Checkbox 82.756 kB 82.865 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Chat 157.915 kB 158.024 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Dialog 116.517 kB 116.626 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Divider 79.065 kB 79.174 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Dropdown 205.958 kB 206.067 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Embed 84.439 kB 84.548 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Form 95.83 kB 95.939 kB ExceedsBaseline     109 bytes
office-ui-fabric-react fluentui-react-northstar-Grid 72.557 kB 72.666 kB ExceedsBaseline     109 bytes

ExceedsTolerance Over Tolerance (1024 B) ExceedsBaseline Over Baseline BelowBaseline Below Baseline New New Deleted  Removed 1 kB = 1000 B

Baseline commit: 625f79c61c8a496a31d19c615a0b8e0d9a72e55b (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 23, 2022

📊 Bundle size report

🤖 This report was generated against 625f79c61c8a496a31d19c615a0b8e0d9a72e55b

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 23, 2022

Perf Analysis (@fluentui/react-northstar)

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
ToolbarMinimalPerf.default 771 668 1.15:1
AttachmentMinimalPerf.default 128 117 1.09:1
PortalMinimalPerf.default 143 133 1.08:1
ButtonSlotsPerf.default 476 445 1.07:1
SegmentMinimalPerf.default 291 275 1.06:1
RadioGroupMinimalPerf.default 371 352 1.05:1
BoxMinimalPerf.default 275 265 1.04:1
DividerMinimalPerf.default 292 282 1.04:1
ListMinimalPerf.default 419 404 1.04:1
CustomToolbarPrototype.default 2441 2350 1.04:1
AnimationMinimalPerf.default 445 433 1.03:1
DialogMinimalPerf.default 648 628 1.03:1
DropdownManyItemsPerf.default 565 550 1.03:1
FormMinimalPerf.default 319 311 1.03:1
HeaderMinimalPerf.default 297 288 1.03:1
TextMinimalPerf.default 283 276 1.03:1
TextAreaMinimalPerf.default 389 378 1.03:1
CardMinimalPerf.default 438 429 1.02:1
ChatDuplicateMessagesPerf.default 241 236 1.02:1
ChatWithPopoverPerf.default 315 308 1.02:1
GridMinimalPerf.default 277 272 1.02:1
InputMinimalPerf.default 1069 1047 1.02:1
LayoutMinimalPerf.default 292 287 1.02:1
MenuMinimalPerf.default 708 695 1.02:1
MenuButtonMinimalPerf.default 1429 1398 1.02:1
ButtonOverridesMissPerf.default 1260 1249 1.01:1
CarouselMinimalPerf.default 384 382 1.01:1
ChatMinimalPerf.default 603 598 1.01:1
EmbedMinimalPerf.default 3429 3383 1.01:1
ItemLayoutMinimalPerf.default 998 985 1.01:1
LabelMinimalPerf.default 319 315 1.01:1
ListCommonPerf.default 518 512 1.01:1
ListNestedPerf.default 454 451 1.01:1
ListWith60ListItems.default 519 512 1.01:1
LoaderMinimalPerf.default 567 562 1.01:1
RosterPerf.default 1774 1765 1.01:1
SkeletonMinimalPerf.default 283 279 1.01:1
StatusMinimalPerf.default 563 559 1.01:1
IconMinimalPerf.default 533 527 1.01:1
CheckboxMinimalPerf.default 2229 2226 1:1
DropdownMinimalPerf.default 2629 2635 1:1
HeaderSlotsPerf.default 632 630 1:1
ProviderMinimalPerf.default 331 330 1:1
ReactionMinimalPerf.default 303 303 1:1
RefMinimalPerf.default 182 182 1:1
SliderMinimalPerf.default 1409 1409 1:1
SplitButtonMinimalPerf.default 3654 3654 1:1
TableManyItemsPerf.default 1550 1553 1:1
VideoMinimalPerf.default 594 592 1:1
ImageMinimalPerf.default 312 316 0.99:1
PopupMinimalPerf.default 520 525 0.99:1
TableMinimalPerf.default 326 328 0.99:1
TreeMinimalPerf.default 660 666 0.99:1
AttachmentSlotsPerf.default 920 939 0.98:1
DatepickerMinimalPerf.default 4740 4828 0.98:1
AlertMinimalPerf.default 212 218 0.97:1
ButtonMinimalPerf.default 126 130 0.97:1
ProviderMergeThemesPerf.default 1028 1056 0.97:1
TooltipMinimalPerf.default 1894 1957 0.97:1
AvatarMinimalPerf.default 150 156 0.96:1
AccordionMinimalPerf.default 113 120 0.94:1
TreeWith60ListItems.default 129 138 0.93:1
FlexMinimalPerf.default 213 233 0.91:1

@YuanboXue-Amber YuanboXue-Amber marked this pull request as ready for review August 23, 2022 11:35
@YuanboXue-Amber YuanboXue-Amber requested a review from a team as a code owner August 23, 2022 11:35
@YuanboXue-Amber YuanboXue-Amber changed the title fix(FocusZone): should reset tabindex on component update when focus is outside fix(FocusZone): should reset tabindex when focus is outside the zone with prop shouldResetActiveElementWhenTabFromZone Aug 23, 2022
@YuanboXue-Amber
Copy link
Contributor Author

/azp run

@microsoft microsoft deleted a comment from azure-pipelines bot Aug 23, 2022
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -1852,4 +1852,66 @@ describe('FocusZone', () => {
expect(buttonB.tabIndex).toBe(-1);
expect(buttonC.tabIndex).toBe(0);
});

it('Update tabIndex when FocusZone is changed before focused', () => {
Copy link
Member

Choose a reason for hiding this comment

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

there is no sense testing this in JSDOM, this should by tested with cypress directly in the browser

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why no sense when the test works as expected? I was initially thinking cypress would be more readable; but eventually did this test as we have all FTZ test here.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly I think most of our tests should be run on browser, they are quite uncomplicated and give us the 'closest' realistic scenario.

Especially for something like focus, it's really browser specific. It's not a blocker but setting up some FZ tests for the browser would be nice

Copy link
Member

@ling1726 ling1726 left a comment

Choose a reason for hiding this comment

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

Honestly this seems like a userland problem if we could expose an imperative ref like we do with popper

const fzRef = React.useRef<FocusZomeImperativeRef>();

fzRef.updateTabIndexes();

...but that opens a whole other can of worms. I couldn't think of a better solution so here is your approval :)

@YuanboXue-Amber YuanboXue-Amber merged commit aa1b9dd into microsoft:master Sep 8, 2022
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Sep 9, 2022
* master: (63 commits)
  feat: add helper types to assist DOM element handling (microsoft#24722)
  applying package updates
  Textarea/hc bug (microsoft#24701)
  Fix null ref in use slider (microsoft#24728)
  Add Field unit tests, and remove snapshot tests (microsoft#24706)
  Stress Test: add build commands (microsoft#24575)
  Coachmark - useOffsetHeight should cause re-render on each set state to match v7 functionality (microsoft#24702)
  Implement screener tests for Field components (microsoft#24684)
  Update Field types to clean up react-field.api.md (microsoft#24703)
  fix(Popup): remove rotate(360deg) from PopupContent content styles (microsoft#24432)
  fix(FocusZone): should reset tabindex when focus is outside the zone with prop `shouldResetActiveElementWhenTabFromZone` (microsoft#24463)
  Fix greyed out legend key contrast ratio (microsoft#24714)
  fix: Portal compat should apply `focus-visible` ponyfill (microsoft#24712)
  Fix artifact error (microsoft#24717)
  chore(react-dialog): remove localShorthands in favor of griffel shorthands (microsoft#24715)
  Skip screener checks for draft PRs with exception of appropriately la… (microsoft#24694)
  fix: Remove provider classname from focus styles (microsoft#24710)
  feat: autocontrolled `useTable` hook (microsoft#24688)
  feat: add dialog properties to getNativeElementProps (microsoft#24698)
  Using migrate rather than upgrade term (microsoft#24695)
  ...
@khmakoto khmakoto added Fluent UI react-northstar (v0) Work related to Fluent UI V0 and removed Fluent UI react-northstar labels Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fluent UI react-northstar (v0) Work related to Fluent UI V0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants