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

Tabs automatically indexing on page load #612

Closed
benpatersonx opened this issue Feb 20, 2023 · 6 comments
Closed

Tabs automatically indexing on page load #612

benpatersonx opened this issue Feb 20, 2023 · 6 comments
Labels
🐛 bug Something isn't working confirmed This bug was confirmed

Comments

@benpatersonx
Copy link

Describe the bug
When you load a page using the tabs component, the first item automatically appears with a focus ring around it or 'indexed' even though it should simply just show as selected. I believe it is an issue with the tab index.

To Reproduce
Steps to reproduce the behavior:

  1. Use the 'Tabs' component from flowbite-react (src/lib/components/Tab/Tabs.tsx)
  2. Load/reload the page
  3. You'll see that the first tab item is automatically focused/indexed (see screenshots)

Expected behavior
All tabs should appear the same until the user interacts with them, apart from the first which should simply be selected not focused like it is.

Screenshots
image

System information:

  • Device: Desktop PC
  • Resolution: 2560 x 1440
  • OS: Windows
  • Browser: Google Chrome
  • Version: 109.0.5414.120

Project information:

  • Tailwind: 3.2.7
  • Flowbite: 1.6.3
  • Flowbite React: 0.3.8
  • Type: NextJS
@tulup-conner tulup-conner added 🐛 bug Something isn't working confirmed This bug was confirmed labels Feb 21, 2023
@evanmays
Copy link

+1

@evanmays
Copy link

Temporary workaround I'm using is to put this hidden button near the top of the page.

<button id="supersecretbutton" style={{width:"0%", height:0, display:"inline", position: "absolute", top:0}} />

Then in the component that holds the flowbite Tab, trigger the new hidden button to be focused after 10ms.

useEffect(() => {
    // run after 0.1 seconds
    setTimeout(() => {
      // horrible
      document.getElementById("supersecretbutton")?.focus()
    }, 10)
  }, [])

You may have to play around with increasing 10ms to something like 100ms.

Note, this solution sucks for accessibility. I'm using it in a prototype product.

The problem with the tab component is it sets focus on the first tab during the initial render
The long term solution is probably to default this state field to -1
https://github.com/themesberg/flowbite-react/blob/main/src/lib/components/Tab/Tabs.tsx#L82
So that this focus doesn't run on first render
https://github.com/themesberg/flowbite-react/blob/main/src/lib/components/Tab/Tabs.tsx#L115

@timomedia
Copy link

+1

@tulup-conner tulup-conner added the help wanted Extra attention is needed label Mar 4, 2023
@timomedia
Copy link

Please help us fix this. Currently if each page uses tabs then when accessing the default url it will select the first tab and automatically jump the scroll bar there. It's exactly like the picture above that @benpatersonx posted.

@ex-oleh
Copy link

ex-oleh commented Mar 30, 2023

focus ring is not the worst thing about this behavior. if you have a card component that has tabs at the bottom of the screen,
the view will always scroll to it on page refresh.

@timomedia
Copy link

@ex-oleh
Yes.
It will always scroll to the section tab when the page loads. This is a pretty bad thing.

paghar added a commit to paghar/flowbite-react that referenced this issue Apr 22, 2023
Automatic focus is deleted on Tab[0]

themesberg#612
paghar added a commit to paghar/flowbite-react that referenced this issue Apr 22, 2023
fix errors on tset file for automatic focus on tab[0]

themesberg#612
rluders pushed a commit that referenced this issue Apr 24, 2023
* fix(tabs): remove tab auto focus

Automatic focus is deleted on Tab[0]

#612

* fix(tabs): update test  auto focus on tabs

fix errors on tset file for automatic focus on tab[0]

#612
@tulup-conner tulup-conner removed the help wanted Extra attention is needed label May 4, 2023
@rluders rluders closed this as completed Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed
Projects
None yet
Development

No branches or pull requests

6 participants