Skip to content
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
4 changes: 3 additions & 1 deletion packages/lab/src/Comments/CommentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ function ThreadSurface({
</VisuallyHidden>
) : null;
const interactionProps = isSelectable ? {onClick, onMouseUp} : {};
// The focus ring comes last. The forced-colors selection outline unsets
// the outline outside forced colors, so it must not override the ring.
const sharedXstyle = [
isSelectable && styles.surface,
isSelectable && isFocused && styles.surfaceFocused,
isFilled && styles.selectedForcedColors,
isSelectable && isFocused && styles.surfaceFocused,
];

if (surface === 'section') {
Expand Down
39 changes: 39 additions & 0 deletions packages/lab/src/Comments/CommentThread.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ vi.mock('../EmojiPicker/emojiData', () => ({
],
}));

import * as stylex from '@stylexjs/stylex';
import {Popover} from '@astryxdesign/core/Popover';
import {focusVars} from '@astryxdesign/core/theme/tokens.stylex';
import {CommentThread, type CommentThreadProps} from './CommentThread';
import {
unsavedDraftOf,
Expand Down Expand Up @@ -210,6 +212,43 @@ describe('CommentThread', () => {
expect(toggle).toHaveFocus();
});

it.each([
['selected', {isSelected: true}, THREAD],
['highlighted', {}, {...THREAD, isHighlighted: true}],
] as const)(
'shows the focus ring on a %s thread that has keyboard focus',
async (_state, props, comment) => {
const user = userEvent.setup();
const focusRing = stylex.create({
ring: {
outlineStyle: focusVars['--focus-outline-style'],
outlineWidth: focusVars['--focus-outline-width'],
},
});
const ringAtoms = stylex
.props(focusRing.ring)
.className!.split(' ')
.filter(name => name.includes('x') && !name.includes('__'));
expect(ringAtoms.length).toBeGreaterThan(0);
render(
<CommentThread
comment={comment}
currentUser={VIEWER}
onSubmit={vi.fn()}
{...props}
/>,
);
await settle();
const toggle = screen.getByRole('button', {name: 'Thread by Maya Chen'});
await user.tab();
expect(toggle).toHaveFocus();
const surface = toggle.closest('[data-thread-surface]');
for (const name of ringAtoms) {
expect(surface).toHaveClass(name);
}
},
);

it('forwards the reply draft lifecycle through a standalone thread', async () => {
const onComposerDraftChange = vi.fn();
const onSubmit = vi.fn().mockResolvedValue(undefined);
Expand Down