Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fd8ed85
Tweak sizing and overflow behavior of TabList.
DaniGuardiola Aug 8, 2024
2dda47d
Add size and overflow playground story.
DaniGuardiola Aug 8, 2024
9979d58
Add "scroll into view" behavior to selected tabs.
DaniGuardiola Aug 8, 2024
cf9e53f
fit-content only on horizontal orientation
DaniGuardiola Aug 8, 2024
bf14552
Reduce specificity of `fit-content` to make it easier to override.
DaniGuardiola Aug 8, 2024
c9777c9
centered label only when orientation is horizontal
DaniGuardiola Aug 8, 2024
e7bf4f0
Remove unused file.
DaniGuardiola Aug 8, 2024
1e94d4d
Fix inspector controls tabs.
DaniGuardiola Aug 8, 2024
1ea21e1
Fix font library modal tabs.
DaniGuardiola Aug 8, 2024
93b2b7f
Fix style-book tabs.
DaniGuardiola Aug 8, 2024
bec645e
fix typo
DaniGuardiola Aug 8, 2024
4f32384
Add changelog entry.
DaniGuardiola Aug 8, 2024
6aefb85
fix emotion being weird ugh
DaniGuardiola Aug 8, 2024
b97b9ba
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Aug 29, 2024
033e89a
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 10, 2024
8be066b
Prevent unwanted focusable container in Firefox.
DaniGuardiola Sep 10, 2024
7ebc4a0
Add fade effect.
DaniGuardiola Sep 11, 2024
4951801
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 11, 2024
141fedc
Fix IntersectionObserver logic.
DaniGuardiola Sep 11, 2024
d5cf0cc
Feature detect IntersectionObserver to prevent tests from failing.
DaniGuardiola Sep 11, 2024
c1095e7
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 12, 2024
22ca3b6
Add a bit of tolerance for scroll state detection.
DaniGuardiola Sep 12, 2024
308a4bf
Fix vertical indicator.
DaniGuardiola Sep 12, 2024
5967da3
Better handling of vertical overflow.
DaniGuardiola Sep 12, 2024
820aede
Add a bit of scroll margin for better "scroll into view" experience.
DaniGuardiola Sep 12, 2024
d6e9336
Horizontal fade should only happen on horizontal direction.
DaniGuardiola Sep 12, 2024
2bcb9ad
Adjust for offset parent scroll state in `getElementOffsetRect`.
DaniGuardiola Sep 12, 2024
879a7e3
Better "scroll into view" positioning heuristics ("nearest").
DaniGuardiola Sep 12, 2024
668120e
Invert use of before and after to remove z-index and fix related issues.
DaniGuardiola Sep 12, 2024
9089219
Make vertical indicator light blue as discussed.
DaniGuardiola Sep 12, 2024
1d064ae
Undo most overrides in pattern/media vertical tabs.
DaniGuardiola Sep 12, 2024
df99501
Clean up outdated styles previously needed for label wrapping.
DaniGuardiola Sep 12, 2024
b7d1f6b
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 17, 2024
d548201
Revert vertical indicator changes and some indicator patterns/media t…
DaniGuardiola Sep 17, 2024
93d1f04
Revert vertical indicator bug fix
DaniGuardiola Sep 17, 2024
bfeee94
Add changelog entry
DaniGuardiola Sep 17, 2024
3a1963e
Remove outdated style.
DaniGuardiola Sep 19, 2024
27586e3
Address feedback
DaniGuardiola Sep 19, 2024
d3d1d84
Fix scroll bug
DaniGuardiola Sep 19, 2024
3460653
Improve automatic tab scrolling behavior.
DaniGuardiola Sep 21, 2024
e6cecec
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 21, 2024
a88179d
Tweaks to prevent unit test failure and minor cleanup.
DaniGuardiola Sep 21, 2024
7327b17
Undo unnecessary changes.
DaniGuardiola Sep 21, 2024
baea996
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 23, 2024
39d4d76
Improved story
DaniGuardiola Sep 23, 2024
c52c74d
Fix scroll jumping bug.
DaniGuardiola Sep 23, 2024
0405ecb
Scroll to active tab instead of selected (support `selectOnMove=false`).
DaniGuardiola Sep 23, 2024
60a5aca
Fix minor visual glitch with overflow fade out indicators.
DaniGuardiola Sep 23, 2024
c821a12
Misc tweaks
DaniGuardiola Sep 23, 2024
8b031f9
Fix.
DaniGuardiola Sep 23, 2024
094509c
Fix changelog
DaniGuardiola Sep 24, 2024
aa18660
Fix changelog but it's actually true
DaniGuardiola Sep 24, 2024
aefb76c
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 27, 2024
5313c62
Fix changelog
DaniGuardiola Sep 27, 2024
c1d5b9f
Make Story Book tabs nicer.
DaniGuardiola Sep 27, 2024
ffbbda2
Temp fix for scrollbar issue in Style Book tabs.
DaniGuardiola Sep 28, 2024
6e02a23
Fix scroll bug and clean up a little.
DaniGuardiola Sep 28, 2024
9aa1d71
Simplify and clean up a bit more.
DaniGuardiola Sep 28, 2024
e73f1d5
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 28, 2024
566401e
Fix merge issues.
DaniGuardiola Sep 28, 2024
83fa634
Fix merge issues again.
DaniGuardiola Sep 28, 2024
e80f76a
Make inserter patterns/media changes more minimal
DaniGuardiola Sep 28, 2024
9b966fe
Fix outdated comment
DaniGuardiola Sep 28, 2024
52102b1
Fix another typo in comment.
DaniGuardiola Sep 28, 2024
1454354
Minor cleanup.
DaniGuardiola Sep 28, 2024
f92e5f2
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
DaniGuardiola Sep 30, 2024
a942b7b
Fix bad automatic merge.
DaniGuardiola Sep 30, 2024
adedb2c
ugh, fix again
DaniGuardiola Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve automatic tab scrolling behavior.
  • Loading branch information
DaniGuardiola committed Sep 21, 2024
commit 34606536960f86cc41d5d8004161b5d4e1916ad0
2 changes: 1 addition & 1 deletion packages/components/src/tabs/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function SizeAndOverflowPlayground() {
? 'Remove width: 100% from TabList'
: 'Set width: 100% in TabList' }
</Button>
<Tabs>
<Tabs defaultTabId="tab4">
<div
style={ {
width: '20rem',
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/tabs/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const Tab = styled( Ariakit.Tab )`
& {
flex-grow: 1;
flex-shrink: 0;
scroll-margin: 2rem;
display: inline-flex;
align-items: center;
position: relative;
Expand Down
41 changes: 35 additions & 6 deletions packages/components/src/tabs/tablist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useStoreState } from '@ariakit/react';
* WordPress dependencies
*/
import warning from '@wordpress/warning';
import { forwardRef, useState } from '@wordpress/element';
import { forwardRef, useEffect, useState } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -43,15 +43,44 @@ export const TabList = forwardRef<
const [ animationEnabled, setAnimationEnabled ] = useState( false );
useOnValueUpdate( selectedId, ( { previousValue } ) => {
if ( previousValue ) {
selectedElement?.scrollIntoView( {
behavior: 'instant',
block: 'nearest',
inline: 'nearest',
} );
setAnimationEnabled( true );
}
} );

// Make sure active tab is scrolled into view.
useEffect( () => {
if ( ! parent || ! indicatorPosition ) {
return;
}

const SCROLL_MARGIN = 24;

function scrollTo( left: number ) {
if ( parent ) {
const originalOverflowX = parent.style.overflowX;
parent.style.overflowX = 'hidden';
parent.scroll( { left } );
parent.style.overflowX = originalOverflowX;
}
}

const { scrollLeft: parentScroll } = parent;
const parentWidth = parent.getBoundingClientRect().width;
const { left: childLeft, width: childWidth } = indicatorPosition;

const parentRightEdge = parentScroll + parentWidth;
const childRightEdge = childLeft + childWidth;
const rightOverflow = childRightEdge + SCROLL_MARGIN - parentRightEdge;
if ( rightOverflow > 0 ) {
return scrollTo( parentScroll + rightOverflow );
}

const leftOverflow = parentScroll - ( childLeft - SCROLL_MARGIN );
if ( leftOverflow > 0 ) {
return scrollTo( parentScroll - leftOverflow );
}
}, [ indicatorPosition, parent ] );

const activeId = useStoreState( context?.store, 'activeId' );
const selectOnMove = useStoreState( context?.store, 'selectOnMove' );

Expand Down
19 changes: 15 additions & 4 deletions packages/components/src/utils/element-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { useEvent } from './hooks/use-event';
* The position and dimensions of an element, relative to its offset parent.
*/
export type ElementOffsetRect = {
/**
* The element the rect belongs to.
*/
element: HTMLElement | undefined;
/**
* The distance from the top edge of the offset parent to the top edge of
* the element.
Expand Down Expand Up @@ -47,6 +51,7 @@ export type ElementOffsetRect = {
* An `ElementOffsetRect` object with all values set to zero.
*/
export const NULL_ELEMENT_OFFSET_RECT = {
element: undefined,
top: 0,
right: 0,
bottom: 0,
Expand Down Expand Up @@ -97,6 +102,7 @@ export function getElementOffsetRect(
const scaleY = computedHeight / rect.height;

return {
element,
// To obtain the adjusted values for the position:
// 1. Compute the element's position relative to the offset parent.
// 2. Correct for the scale factor.
Expand Down Expand Up @@ -124,6 +130,9 @@ const POLL_RATE = 100;
* Tracks the position and dimensions of an element, relative to its offset
* parent. The element can be changed dynamically.
*
* When no element is provided (`null` or `undefined`), the hook will return
* a "null" rect, in which all values are `0` and `element` is `undefined`.
*
* **Note:** sometimes, the measurement will fail (see `getElementOffsetRect`'s
* documentation for more details). When that happens, this hook will attempt
* to measure again after a frame, and if that fails, it will poll every 100
Expand Down Expand Up @@ -160,10 +169,12 @@ export function useTrackElementOffsetRect(
}
} );

useLayoutEffect(
() => setElement( targetElement ),
[ setElement, targetElement ]
);
useLayoutEffect( () => {
setElement( targetElement );
if ( ! targetElement ) {
setIndicatorPosition( NULL_ELEMENT_OFFSET_RECT );
}
}, [ setElement, targetElement ] );

return indicatorPosition;
}
Expand Down