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

Updated tab item focus to wait for the next frame #12335

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

AndrewMusgrave
Copy link
Member

@AndrewMusgrave AndrewMusgrave commented Jul 3, 2024

WHY are these changes introduced?

Fixes #11829

WHAT is this pull request doing?

Using the same pattern as popover overlay to delay focusing to the next frame (for measuring/positioning)

Giphy

Before

Monosnap.screencast.2024-07-03.16-41-53.mp4

After

Monosnap.screencast.2024-07-03.16-41-16.mp4

How to 🎩

Playground code ⬇️

import React, {useState} from 'react';

import {Page, Box, Tabs} from '../src';

const tabs = [
  {content: 'Hello1', id: '1'},
  {content: 'Hello2', id: '2'},
  {content: 'Hello3', id: '3'},
  {content: 'Hello4', id: '4'},
  {content: 'Hello5', id: '5'},
  {content: 'Hello6', id: '6'},
  {content: 'Hello7', id: '7'},
  {content: 'Hello8', id: '8'},
  {content: 'Hello9', id: '9'},
  {content: 'Hello10', id: '10'},
  {content: 'Hello11', id: '11'},
  {content: 'Hello12', id: '12'},
  {content: 'Hello13', id: '13'},
  {content: 'Hello14', id: '14'},
  {content: 'Hello15', id: '15'},
];

export const Playground = {
  tags: ['skip-tests'],
  render() {
    const [selected, setSelected] = useState(0);

    return (
      <Page narrowWidth>
        <Box background="avatar-five-bg-fill" minHeight="4000px" />
        <Tabs tabs={tabs} selected={selected} onSelect={setSelected} />
      </Page>
    );
  },
};

Notes

While tophatting I noticed some odd behavior with how the focus styles are applied. We're using the focus visible selector, but manually sending focus. This is causing the browser to sometimes not display the focus ring - I noticed it the most on firefox.

🎩 checklist

@AndrewMusgrave
Copy link
Member Author

/snapit

Copy link
Contributor

github-actions bot commented Jul 3, 2024

🫰✨ Thanks @AndrewMusgrave! Your snapshot has been published to npm.

Test the snapshot by updating your package.json with the newly published version:

"@shopify/polaris": "0.0.0-snapshot-20240703204424"

@AndrewMusgrave AndrewMusgrave marked this pull request as ready for review July 3, 2024 21:28
focused
) {
focusedNode.current.focus();
const focusTarget = focusedNode.current;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed to keep the variable within scope for the RAF

const focusTarget = focusedNode.current;

if (focusTarget && focusTarget instanceof HTMLElement && focused) {
requestAnimationFrame(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@lgriffee lgriffee left a comment

Choose a reason for hiding this comment

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

Tophat and code LGTM! 🎩✨ Thanks for much for this fix Andrew! Let me just tag one more Polaris dev for a second review since Chloe is out for a bit.

While tophatting I noticed some odd behavior with how the focus styles are applied. We're using the focus visible selector, but manually sending focus. This is causing the browser to sometimes not display the focus ring - I noticed it the most on firefox.

I wasn't able to reproduce this while tophatting 🤔 Would you mind adding a video to a new issue so I can try to reproduce this? And was this happening prior to your fix? If so, we can keep this separate from these changes.

@lgriffee lgriffee requested a review from a team July 8, 2024 17:33
@AndrewMusgrave
Copy link
Member Author

@lgriffee I wish I did take a video, I'm having trouble reproducing it again! However, it was on main. The core of the issue was we're manually setting focus, and whatever heuristic the focus-visible selector is using wasn't met.

@AndrewMusgrave AndrewMusgrave merged commit d71b3a2 into main Jul 9, 2024
12 of 13 checks passed
@AndrewMusgrave AndrewMusgrave deleted the am-tabs-more-tabs-focus branch July 9, 2024 16:25
alex-page pushed a commit that referenced this pull request Jul 16, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris@13.7.0

### Minor Changes

- [#12341](#12341)
[`f6728a410`](f6728a4)
Thanks [@AndrewMusgrave](https://github.com/AndrewMusgrave)! - Exposed a
`close` function on popovers imperative handle

### Patch Changes

- [#12335](#12335)
[`d71b3a282`](d71b3a2)
Thanks [@AndrewMusgrave](https://github.com/AndrewMusgrave)! - Fixed
`Tabs` automatically closing when opened in a scrolled position

- Updated dependencies
\[[`b4cbdefd4`](b4cbdef)]:
    -   @shopify/polaris-tokens@9.3.0

## @shopify/polaris-tokens@9.3.0

### Minor Changes

- [#12398](#12398)
[`b4cbdefd4`](b4cbdef)
Thanks [@alex-page](https://github.com/alex-page)! - Update the green
and red token values

## @shopify/polaris-migrator@1.0.4

### Patch Changes

- Updated dependencies
\[[`b4cbdefd4`](b4cbdef)]:
    -   @shopify/polaris-tokens@9.3.0
    -   @shopify/stylelint-polaris@16.0.4

## @shopify/stylelint-polaris@16.0.4

### Patch Changes

- Updated dependencies
\[[`b4cbdefd4`](b4cbdef)]:
    -   @shopify/polaris-tokens@9.3.0

## polaris-for-vscode@1.0.4

### Patch Changes

- Updated dependencies
\[[`b4cbdefd4`](b4cbdef)]:
    -   @shopify/polaris-tokens@9.3.0

## polaris.shopify.com@1.0.10

### Patch Changes

- Updated dependencies
\[[`b4cbdefd4`](b4cbdef),
[`d71b3a282`](d71b3a2),
[`f6728a410`](f6728a4)]:
    -   @shopify/polaris-tokens@9.3.0
    -   @shopify/polaris@13.7.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants