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

Fine-tune delays in Tooltip and associated components #2368

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/seven-parents-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Fine-tuned tooltip delays in `Tooltip` and other components that use `Tooltip` internally.
2 changes: 1 addition & 1 deletion apps/react-workshop/src/AvatarGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('AvatarGroup', () => {

if (testName.includes('Tooltip')) {
cy.get('div').contains('3').trigger('mouseenter');
cy.wait(50);
cy.wait(100);
}

cy.compareSnapshot(testName);
Expand Down
2 changes: 1 addition & 1 deletion apps/react-workshop/src/Breadcrumbs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Breadcrumbs', () => {
cy.get('button').eq(1).click();
} else if (testName === 'Custom Overflow Back Button') {
cy.get('button').eq(1).trigger('mouseenter');
cy.wait(60);
cy.wait(100);
}

cy.compareSnapshot(testName);
Expand Down
2 changes: 1 addition & 1 deletion apps/react-workshop/src/Stepper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Stepper', () => {
if (testName.includes('Tooltip')) {
cy.get('#ladle-root').within(() => {
cy.get('li').first().trigger('mouseenter'); // trigger tooltip
cy.wait(50);
cy.wait(100);
});
}

Expand Down
2 changes: 1 addition & 1 deletion apps/react-workshop/src/Tooltip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Tooltip', () => {
const id = Cypress.storyId(storyPath, testName);
cy.visit('/', { qs: { mode: 'preview', story: id } });
cy.get('#tooltip-target').trigger('mouseenter');
cy.wait(50);
cy.wait(100);
cy.compareSnapshot(testName);
});
});
Expand Down
2 changes: 1 addition & 1 deletion apps/react-workshop/src/WorkflowDiagram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('WorkflowDiagram', () => {
if (testName.includes('Tooltip')) {
cy.get('#ladle-root').within(() => {
cy.get('li').first().trigger('mouseenter'); // trigger tooltip
cy.wait(50);
cy.wait(100);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const ButtonGroup = React.forwardRef((props, forwardedRef) => {
);

return (
<FloatingDelayGroup delay={{ open: 50, close: 250 }}>
<FloatingDelayGroup delay={{ open: 100, close: 200 }}>
<ButtonGroupContext.Provider value={orientation}>
{props.role === 'toolbar' ? (
<Composite
Expand Down
57 changes: 30 additions & 27 deletions packages/itwinui-react/src/core/SideNavigation/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { IconButton } from '../Buttons/IconButton.js';
import { FloatingDelayGroup } from '@floating-ui/react';

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -142,41 +143,43 @@ export const SideNavigation = React.forwardRef((props, forwardedRef) => {
className={cx('iui-side-navigation-wrapper', wrapperProps?.className)}
ref={forwardedRef}
>
<Box
as='div'
className={cx(
'iui-side-navigation',
{
'iui-expanded': isExpanded,
'iui-collapsed': !isExpanded,
},
className,
)}
{...rest}
>
{expanderPlacement === 'top' && ExpandButton}
<FloatingDelayGroup delay={{ open: 100, close: 200 }}>
<Box
as='div'
{...contentProps}
className={cx('iui-sidenav-content', contentProps?.className)}
className={cx(
'iui-side-navigation',
{
'iui-expanded': isExpanded,
'iui-collapsed': !isExpanded,
},
className,
)}
{...rest}
>
{expanderPlacement === 'top' && ExpandButton}
<Box
as='div'
{...topProps}
className={cx('iui-top', topProps?.className)}
{...contentProps}
className={cx('iui-sidenav-content', contentProps?.className)}
>
{items}
</Box>
<Box
as='div'
{...bottomProps}
className={cx('iui-bottom', bottomProps?.className)}
>
{secondaryItems}
<Box
as='div'
{...topProps}
className={cx('iui-top', topProps?.className)}
>
{items}
</Box>
<Box
as='div'
{...bottomProps}
className={cx('iui-bottom', bottomProps?.className)}
>
{secondaryItems}
</Box>
</Box>
{expanderPlacement === 'bottom' && ExpandButton}
</Box>
{expanderPlacement === 'bottom' && ExpandButton}
</Box>
</FloatingDelayGroup>

{submenu && (
<WithCSSTransition
Expand Down
89 changes: 46 additions & 43 deletions packages/itwinui-react/src/core/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { Track } from './Track.js';
import { Thumb } from './Thumb.js';
import type { Tooltip } from '../Tooltip/Tooltip.js';
import { FloatingDelayGroup } from '@floating-ui/react';

/**
* Determines which segments are shown with color.
Expand Down Expand Up @@ -492,49 +493,51 @@ export const Slider = React.forwardRef((props, ref) => {
{minValueLabel}
</Box>
)}
<Box
ref={containerRef}
{...trackContainerProps}
className={cx(
'iui-slider',
{
'iui-grabbing': undefined !== activeThumbIndex,
},
trackContainerProps?.className,
)}
onPointerDown={handlePointerDownOnSlider}
>
{currentValues.map((thumbValue, index) => {
const [minVal, maxVal] = getAllowableThumbRange(index);
const thisThumbProps = thumbProps?.(index);
return (
<Thumb
key={thisThumbProps?.id ?? index}
index={index}
disabled={disabled}
isActive={activeThumbIndex === index}
onThumbActivated={onThumbActivated}
onThumbValueChanged={onThumbValueChanged}
minVal={minVal}
maxVal={maxVal}
value={thumbValue}
tooltipProps={generateTooltipProps(index, thumbValue)}
thumbProps={thisThumbProps}
step={step}
sliderMin={min}
sliderMax={max}
/>
);
})}
<Track
trackDisplayMode={trackDisplay}
sliderMin={min}
sliderMax={max}
values={currentValues}
orientation={orientation}
{...trackProps}
/>
</Box>
<FloatingDelayGroup delay={{ open: 100, close: 200 }}>
<Box
ref={containerRef}
{...trackContainerProps}
className={cx(
'iui-slider',
{
'iui-grabbing': undefined !== activeThumbIndex,
},
trackContainerProps?.className,
)}
onPointerDown={handlePointerDownOnSlider}
>
{currentValues.map((thumbValue, index) => {
const [minVal, maxVal] = getAllowableThumbRange(index);
const thisThumbProps = thumbProps?.(index);
return (
<Thumb
key={thisThumbProps?.id ?? index}
index={index}
disabled={disabled}
isActive={activeThumbIndex === index}
onThumbActivated={onThumbActivated}
onThumbValueChanged={onThumbValueChanged}
minVal={minVal}
maxVal={maxVal}
value={thumbValue}
tooltipProps={generateTooltipProps(index, thumbValue)}
thumbProps={thisThumbProps}
step={step}
sliderMin={min}
sliderMax={max}
/>
);
})}
<Track
trackDisplayMode={trackDisplay}
sliderMin={min}
sliderMax={max}
values={currentValues}
orientation={orientation}
{...trackProps}
/>
</Box>
</FloatingDelayGroup>
{tickMarkArea}
{maxValueLabel && (
<Box
Expand Down
4 changes: 2 additions & 2 deletions packages/itwinui-react/src/core/Stepper/Stepper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ it('should display tooltip upon hovering step if description provided', async ()

expect(document.querySelector('.iui-tooltip')).not.toBeVisible();
fireEvent.mouseEnter(screen.getByText('Step One'), { bubbles: true });
act(() => void vi.advanceTimersByTime(50));
act(() => void vi.advanceTimersByTime(100));
const tooltip = document.querySelector('.iui-tooltip') as HTMLElement;
expect(tooltip).toBeVisible();
expect(tooltip).toHaveTextContent('Step one tooltip');
Expand All @@ -282,7 +282,7 @@ it('should display tooltip upon hovering step if description provided', async ()
act(() => void vi.advanceTimersByTime(250));

fireEvent.mouseEnter(screen.getByText('Step Three'), { bubbles: true });
act(() => void vi.advanceTimersByTime(50));
act(() => void vi.advanceTimersByTime(200));
expect(tooltip).not.toBeVisible();

vi.useRealTimers();
Expand Down
53 changes: 28 additions & 25 deletions packages/itwinui-react/src/core/Stepper/Stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as React from 'react';
import { Box } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { StepperStep } from './StepperStep.js';
import { FloatingDelayGroup } from '@floating-ui/react';

export type StepperLocalization = {
stepsCountLabel: (currentStep: number, totalSteps: number) => string;
Expand Down Expand Up @@ -103,31 +104,33 @@ export const Stepper = React.forwardRef((props, ref) => {

return (
<Box className={'iui-stepper'} ref={ref} {...rest}>
<ol>
{steps.map((s, index) => {
const thisStepProps = stepProps?.(index);
const thisTrackContentProps = trackContentProps?.(index);
const thisCircleProps = circleProps?.(index);
const thisNameProps = nameProps?.(index);
return (
<StepperStep
stepProps={thisStepProps}
trackContentProps={thisTrackContentProps}
circleProps={thisCircleProps}
nameProps={thisNameProps}
key={index}
index={index}
title={type === 'long' ? '' : s.name}
currentStepNumber={boundedCurrentStep}
totalSteps={steps.length}
type={type}
onClick={onStepClick}
description={s.description}
stepContent={s.stepContent}
/>
);
})}
</ol>
<FloatingDelayGroup delay={{ open: 100, close: 200 }}>
<ol>
{steps.map((s, index) => {
const thisStepProps = stepProps?.(index);
const thisTrackContentProps = trackContentProps?.(index);
const thisCircleProps = circleProps?.(index);
const thisNameProps = nameProps?.(index);
return (
<StepperStep
stepProps={thisStepProps}
trackContentProps={thisTrackContentProps}
circleProps={thisCircleProps}
nameProps={thisNameProps}
key={index}
index={index}
title={type === 'long' ? '' : s.name}
currentStepNumber={boundedCurrentStep}
totalSteps={steps.length}
type={type}
onClick={onStepClick}
description={s.description}
stepContent={s.stepContent}
/>
);
})}
</ol>
</FloatingDelayGroup>
{type === 'long' && (
<Box
as='div'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ it('should display tooltip upon hovering step if description provided', async ()

expect(document.querySelector('.iui-tooltip')).not.toBeVisible();
fireEvent.mouseEnter(screen.getByText('Step One'), { bubbles: true });
act(() => void vi.advanceTimersByTime(50));
act(() => void vi.advanceTimersByTime(100));
const tooltip = document.querySelector('.iui-tooltip') as HTMLElement;
expect(tooltip).toBeVisible();
expect(tooltip).toHaveTextContent('Step one tooltip');
Expand All @@ -90,7 +90,7 @@ it('should display tooltip upon hovering step if description provided', async ()
act(() => void vi.advanceTimersByTime(250));

fireEvent.mouseEnter(screen.getByText('Step Three'), { bubbles: true });
act(() => void vi.advanceTimersByTime(50));
act(() => void vi.advanceTimersByTime(100));
expect(document.querySelector('.iui-tooltip')).not.toBeVisible();

vi.useRealTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const useTooltip = (options: TooltipOptions = {}) => {

const interactions = useInteractions([
useHover(floating.context, {
delay: delay !== 0 ? delay : { open: 50, close: 250 }, // If FloatingDelayGroup exists, use its delay
delay: delay !== 0 ? delay : { open: 100, close: 200 }, // If FloatingDelayGroup exists, use its delay
handleClose: safePolygon({ buffer: -Infinity }),
move: false,
}),
Expand Down
Loading