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: interactive tile expand button #16644

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
51 changes: 45 additions & 6 deletions e2e/components/Tile/Tile-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ test.describe('@avt Tile', () => {
},
});
await expect(page.locator('body')).toBeFocused();

// Pause to ensure the initial animation finishes before we interact
await expect(
page.getByRole('button', { name: 'Above the fold content here' })
).toBeVisible();

await page.keyboard.press('Tab');
await expect(page.locator('#expandable-tile-1')).toBeFocused();
await page.keyboard.press('Enter');
Expand All @@ -109,7 +115,32 @@ test.describe('@avt Tile', () => {
);
});

test('@avt-keyboard-nav SelectableTile', async ({ page }) => {
test('@avt-advanced-states ExpandableTile with interactive spacebar', async ({
page,
}) => {
await visitStory(page, {
component: 'ExpandableTile',
id: 'components-tile--expandable-with-interactive',
globals: {
theme: 'white',
},
});
await expect(page.locator('body')).toBeFocused();

// Pause to ensure the initial animation finishes before we interact
await expect(page.getByLabel('Interact to Expand tile')).toBeVisible();

await page.keyboard.press('Tab');
await page.keyboard.press('Tab');

await expect(page.getByLabel('Interact to Expand tile')).toBeFocused();
await page.keyboard.press('Space');
await expect(page.locator('#expandable-tile-1')).toHaveClass(
'cds--tile cds--tile--expandable cds--tile--expandable--interactive cds--tile--is-expanded'
);
});

test.only('@avt-keyboard-nav SelectableTile', async ({ page }) => {
await visitStory(page, {
component: 'SelectableTile',
id: 'components-tile--selectable',
Expand All @@ -118,15 +149,19 @@ test.describe('@avt Tile', () => {
},
});
await expect(page.locator('body')).toBeFocused();

// Pause to ensure the initial animation finishes before we interact
await expect(page.getByRole('checkbox')).toBeVisible();

await page.keyboard.press('Tab');
await expect(page.locator('#selectable-tile-1')).toBeFocused();
await expect(page.getByRole('checkbox')).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.locator('#selectable-tile-1')).toHaveClass(
await expect(page.getByRole('checkbox')).toHaveClass(
'cds--tile cds--tile--selectable cds--tile--is-selected'
);
});

test('@avt-keyboard-nav RadioTile', async ({ page }) => {
test.only('@avt-keyboard-nav RadioTile', async ({ page }) => {
await visitStory(page, {
component: 'RadioTile',
id: 'components-tile--radio',
Expand All @@ -135,9 +170,13 @@ test.describe('@avt Tile', () => {
},
});
await expect(page.locator('body')).toBeFocused();

// Pause to ensure the initial animation finishes before we interact
await expect(page.getByRole('radio').nth(0)).toBeVisible();

await page.keyboard.press('Tab');
await expect(page.locator('#radio-tile-2')).toBeFocused();
await expect(page.getByRole('radio').nth(1)).toBeFocused();
await page.keyboard.press('ArrowUp');
await expect(page.locator('#radio-tile-1')).toBeChecked();
await expect(page.getByRole('radio').nth(0)).toBeChecked();
});
});
7 changes: 6 additions & 1 deletion packages/react/src/components/Tile/Tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ export const ExpandableTile = React.forwardRef<
const [interactive, setInteractive] = useState<boolean>(true);
const aboveTheFold = useRef<HTMLDivElement>(null);
const belowTheFold = useRef<HTMLDivElement>(null);
const chevronInteractiveRef = useRef<HTMLButtonElement>(null);
const tileContent = useRef<HTMLDivElement>(null);
const tile = useRef<HTMLElement>(null);
const ref = useMergedRefs([forwardRef, tile]);
Expand Down Expand Up @@ -745,7 +746,10 @@ export const ExpandableTile = React.forwardRef<
}

function handleKeyUp(evt: KeyboardEvent) {
if (evt.target !== tile.current) {
if (
evt.target !== tile.current &&
evt.target !== chevronInteractiveRef.current
) {
if (matches(evt, [keys.Enter, keys.Space])) {
evt.preventDefault();
}
Expand Down Expand Up @@ -876,6 +880,7 @@ export const ExpandableTile = React.forwardRef<
onKeyUp={composeEventHandlers([onKeyUp, handleKeyUp])}
onClick={composeEventHandlers([onClick, handleClick])}
aria-label={isExpanded ? tileExpandedIconText : tileCollapsedIconText}
ref={chevronInteractiveRef}
className={chevronInteractiveClassNames}>
<ChevronDown />
</button>
Expand Down
Loading