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

feature(react-tree): preventScroll on navigation #31577

Conversation

bsunderhus
Copy link
Contributor

@bsunderhus bsunderhus commented Jun 5, 2024

Previous Behavior

In the nested tree when navigating, we focus on the TreeItem itself and since that item includes all its children nested inside of it the browser will automatically scroll that whole item into view (see #31557).

New Behavior

  1. adds preventScroll and isScrollPrevented methods to onNavigation data parameter. When preventScroll is invoked then the navigation focus will not scroll to the element while focusing (see preventScroll)

With this feature now it's possible to maintain navigation as is while opting out of the scroll mechanism, allowing the user to create its own (in the case of #31557 we could just scroll into the TreeItemLayout instead of the TreeItem when navigating)

const handleNavigation: TreeProps['onNavigation'] = (_event, data) => {
  data.preventScroll();
  // request animation frame to wait for the active element to be updated
  targetDocument?.defaultView?.requestAnimationFrame(() => {
    const layoutElement = targetDocument?.activeElement?.querySelector<HTMLElement>(
      `.${treeItemLayoutClassNames.root}`,
    );
    if (layoutElement && !isElementInViewport(layoutElement)) {
      layoutElement.scrollIntoView({ block: 'nearest', behavior: 'auto' });
    }
  });
};

Related Issue(s)

@bsunderhus bsunderhus self-assigned this Jun 5, 2024
@github-actions github-actions bot added this to the April Project Cycle Q1 2024 milestone Jun 5, 2024
@bsunderhus bsunderhus marked this pull request as ready for review June 5, 2024 09:13
@bsunderhus bsunderhus requested a review from a team as a code owner June 5, 2024 09:13
@fabricteam
Copy link
Collaborator

fabricteam commented Jun 5, 2024

Perf Analysis (@fluentui/react-components)

Scenario Render type Master Ticks PR Ticks Iterations Status
FluentProviderWithTheme mount 76 87 10 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 638 626 5000
Button mount 309 308 5000
Field mount 1134 1141 5000
FluentProvider mount 692 702 5000
FluentProviderWithTheme mount 76 87 10 Possible regression
FluentProviderWithTheme virtual-rerender 42 34 10
FluentProviderWithTheme virtual-rerender-with-unmount 74 76 10
MakeStyles mount 881 869 50000
Persona mount 1766 1731 5000
SpinButton mount 1424 1416 5000
SwatchPicker mount 1549 1541 5000

Copy link

codesandbox-ci bot commented Jun 5, 2024

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.

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 5, 2024

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: entire library
1.092 MB
269.585 kB
1.092 MB
269.637 kB
110 B
52 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Button, FluentProvider & webLightTheme
69.141 kB
20.157 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
212.636 kB
61.23 kB
react-components
react-components: FluentProvider & webLightTheme
44.442 kB
14.607 kB
react-portal-compat
PortalCompatProvider
8.39 kB
2.64 kB
🤖 This report was generated against f0fd89b619b2e8bb520b08f1face7aaad9adfdb2

@bsunderhus bsunderhus requested a review from ling1726 June 5, 2024 09:37
Copy link

codesandbox-ci bot commented Jun 5, 2024

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.

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 5, 2024

🕵 fluentuiv9 No visual regressions between this PR and main

Copy link

codesandbox-ci bot commented Jun 5, 2024

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.

@bsunderhus bsunderhus merged commit f49888c into microsoft:master Jun 5, 2024
19 of 20 checks passed
@bsunderhus bsunderhus deleted the react-tree/feature--preventScroll-on-navigation branch June 5, 2024 11:47
miroslavstastny pushed a commit to miroslavstastny/fluentui that referenced this pull request Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Scroll jump when navigating nested tree using keyboard
4 participants