-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: remove custom logic #66097
Tabs: remove custom logic #66097
Conversation
cf400cb
to
b61a2d3
Compare
Size Change: -23 B (0%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
const selectedTabId = selectedCategory ? selectedCategory.name : null; | ||
const [ activeTabId, setActiveId ] = useState(); | ||
const firstTabId = categories?.[ 0 ]?.name; | ||
useEffect( () => { | ||
// If there is no active tab, make the first tab the active tab, so that | ||
// when focus is moved to the tablist, the first tab will be focused | ||
// despite not being selected | ||
if ( selectedTabId === null && ! activeTabId && firstTabId ) { | ||
setActiveId( firstTabId ); | ||
} | ||
}, [ selectedTabId, activeTabId, firstTabId, setActiveId ] ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested on the Patterns tab of the inserter, and confirmed it focuses the first tab without activating it. It works the same as on trunk. Thanks!
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I think this PR is ready for a first round of review / smoke testing, at least to get a feeling about whether we're moving in the right direction. |
b61a2d3
to
0d43fd4
Compare
@ciampo sorry - I couldn't make it to testing and reviewing this one today, but planning to devote some time tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I've double-checked the custom behaviors and didn't spot anything unexpected.
Thanks @ciampo, this is a great cleanup 🚀
- Better descriptions - Add initially selected tab assertion to wait for Ariakit first render
- If a tab is disabled, the matching tabpanel is still shown?
A selected tab can be disabled at the same time. If this doesn't work out for the consumer, they can tweak the behavior by controlling the tab
The performance impact of this PR on inserter opening is impressive: |
A good reminder that we should aim for simplicity when possible. Low-level components can have many instances rendered at once, and even a small improvement can make a big difference in the metrics 🥳 |
@ciampo Curious, what has changed here? Just rendering less components? |
@ellatrix we removed a few hooks that were applying some logic to The tabs in the inserter sidebar used some (but not all) of that logic, and so we only re-added the necessary bits (see #66097 (comment)) |
Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
What?
Related to #66011
Remove most custom logic in the
Tabs
componentWhy?
For a detailed explanation of the logic being removed, refer to the behaviors 1 to 4 listed in #66011. Behavior 6 is being kept for the time being, while the logic is incorporated directly in
ariakit
(see ariakit/ariakit#4213).How?
Custom logic being removed (from #66011):
Process:
Testing Instructions
Specific behaviours to check:
selectedId
ordefaultSelectedId
props are passed and refer to an existing tab id,Tabs
will automatically select the first non-disabled tab and shows related tab-panel;selectedId
ordefaultSelectedId
props are passed but refer to a tab id that doesn't exist,Tabs
won't show any tabs as selected and won't show any tabpanels;selectedId
prop is passed but refers to a tab id that doesn't exist, and the tab is later added to the react tree,Tabs
will correctly select that tab; this won't work withdefaultSelectedId
, since that prop only works for the initial render;selectedId
ordefaultSelectedId
props have a value ofnull
, no tabs will be selected and no tabpanels will be shown, and the tablist itself will become tabbable; when focus in on the tablist, pressing arrow keys will select tabs;selectedId
ordefaultSelectedId
props are passed and refer to a disabled tab, that tab will be selected anyway (and its associated tabpanel will be shown);Note: there is a toolbar e2e test that is expected to fail, since this PR is currently based off #65907.
For added context, here is also a (potentially incomplete) history of recent changes to the
Tabs
component, specifically to how it handles initial selection, disabled tabs, removed tabs, and general focus handling:activeId
updates until focus can be properly detected #58625