Skip to content

Commit e5d2e7b

Browse files
committed
Fix buttons on focus
1 parent 190efeb commit e5d2e7b

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

packages/module/src/MessageBox/JumpButton.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
inset-block-end: var(--pf-t--global--spacer--md) !important;
4545
}
4646

47+
// inclusively hidden: stay in tab order but reveal on keyboard focus
48+
// https://css-tricks.com/inclusively-hidden/
49+
&--hidden:not(:focus):not(:focus-visible):not(:active) {
50+
clip: rect(0 0 0 0);
51+
clip-path: inset(50%);
52+
height: 1px !important;
53+
overflow: hidden;
54+
white-space: nowrap;
55+
width: 1px !important;
56+
}
57+
58+
&--hidden:focus,
59+
&--hidden:focus-visible,
60+
&--hidden:active {
61+
clip: auto;
62+
clip-path: none;
63+
height: 2rem !important;
64+
overflow: visible;
65+
white-space: normal;
66+
width: 2rem !important;
67+
}
68+
4769
// allows for zoom conditions; try zooming to 200% to see
4870
@media screen and (max-height: 518px) {
4971
display: none;

packages/module/src/MessageBox/JumpButton.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ describe('JumpButton', () => {
2121
it('should remain in the DOM but visually hidden when isHidden is used', () => {
2222
render(<JumpButton position="bottom" onClick={jest.fn()} isHidden />);
2323
const button = screen.getByRole('button', { name: /Back to bottom/i });
24-
expect(button).toHaveClass('pf-chatbot-m-hidden');
24+
expect(button).toHaveClass('pf-chatbot__jump--hidden');
2525
});
2626

2727
it('should become visible when focused while hidden', () => {
2828
render(<JumpButton position="bottom" onClick={jest.fn()} isHidden />);
2929
const button = screen.getByRole('button', { name: /Back to bottom/i });
3030
button.focus();
3131
expect(button).toHaveFocus();
32-
expect(button).toHaveClass('pf-chatbot-m-hidden');
32+
expect(button).toHaveClass('pf-chatbot__jump--hidden');
3333
});
3434
});

packages/module/src/MessageBox/JumpButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const JumpButton: FunctionComponent<JumpButtonProps> = ({
3737
>
3838
<Button
3939
variant="plain"
40-
className={`pf-chatbot__jump pf-chatbot__jump--${position} ${isHidden ? 'pf-chatbot-m-hidden' : ''}`}
40+
className={`pf-chatbot__jump pf-chatbot__jump--${position} ${isHidden ? 'pf-chatbot__jump--hidden' : ''}`}
4141
aria-label={`Back to ${position}`}
4242
onClick={onClick}
4343
{...jumpButtonProps}

packages/module/src/MessageBox/MessageBox.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ describe('MessageBox', () => {
378378
});
379379

380380
await waitFor(() => {
381-
expect(screen.getByRole('button', { name: /Back to top/i })).toHaveClass('pf-chatbot-m-hidden');
382-
expect(screen.getByRole('button', { name: /Back to bottom/i })).not.toHaveClass('pf-chatbot-m-hiddenn');
381+
expect(screen.getByRole('button', { name: /Back to top/i })).toHaveClass('pf-chatbot__jump--hidden');
382+
expect(screen.getByRole('button', { name: /Back to bottom/i })).not.toHaveClass('pf-chatbot__jump--hidden');
383383
});
384384
});
385385

@@ -400,8 +400,8 @@ describe('MessageBox', () => {
400400
});
401401

402402
await waitFor(() => {
403-
expect(screen.getByRole('button', { name: /Back to top/i })).not.toHaveClass('pf-chatbot-m-hidden');
404-
expect(screen.getByRole('button', { name: /Back to bottom/i })).toHaveClass('pf-chatbot-m-hidden');
403+
expect(screen.getByRole('button', { name: /Back to top/i })).not.toHaveClass('pf-chatbot__jump--hidden');
404+
expect(screen.getByRole('button', { name: /Back to bottom/i })).toHaveClass('pf-chatbot__jump--hidden');
405405
});
406406
});
407407
});

0 commit comments

Comments
 (0)