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

Fix: Align tooltip with others element spacing wise #64454

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from
16 changes: 16 additions & 0 deletions packages/block-editor/src/components/block-mover/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ const getArrowIcon = ( direction, orientation ) => {
return null;
};

const getDirection = ( direction, orientation ) => {
if ( direction === 'up' ) {
if ( orientation === 'horizontal' ) {
return isRTL() ? 'right' : 'left';
}
return 'up';
} else if ( direction === 'down' ) {
if ( orientation === 'horizontal' ) {
return isRTL() ? 'left' : 'right';
}
return 'down';
}
return null;
};

const getMovementDirectionLabel = ( moveDirection, orientation ) => {
if ( moveDirection === 'up' ) {
if ( orientation === 'horizontal' ) {
Expand Down Expand Up @@ -139,6 +154,7 @@ const BlockMoverButton = forwardRef(
direction,
orientation
) }
tooltipPosition={ getDirection( direction, orientation ) }
aria-describedby={ descriptionId }
{ ...props }
onClick={ isDisabled ? null : onClick }
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export function UnforwardedButton(
tooltipPosition &&
// Convert legacy `position` values to be used with the new `placement` prop
positionToPlacement( tooltipPosition ),
direction: tooltipPosition,
}
: {};

Expand Down
14 changes: 12 additions & 2 deletions packages/components/src/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function UnforwardedTooltip(
position,
shortcut,
text,

direction,
...restProps
} = props;

Expand Down Expand Up @@ -93,6 +93,16 @@ function UnforwardedTooltip(
placement: computedPlacement,
showTimeout: delay,
} );

const getGutterValue = () => {
if ( direction === 'up' ) {
return 28;
} else if ( direction === 'down' ) {
return 8;
}
return 4;
};

const mounted = tooltipStore.useState( 'mounted' );

if ( isNestedInTooltip ) {
Expand Down Expand Up @@ -130,7 +140,7 @@ function UnforwardedTooltip(
{ ...restProps }
className={ clsx( 'components-tooltip', className ) }
unmountOnHide
gutter={ 4 }
gutter={ getGutterValue() }
id={ describedById }
overflowPadding={ 0.5 }
store={ tooltipStore }
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/tooltip/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
.components-tooltip__shortcut {
margin-left: $grid-unit-10;
}

4 changes: 4 additions & 0 deletions packages/components/src/tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export type TooltipProps = {
* The text shown in the tooltip when anchor element is focused or hovered.
*/
text?: string;
/**
* The direction of the tooltip arrow.
*/
direction?: string;
};

export type TooltipInternalContext = {
Expand Down
Loading