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
19 changes: 19 additions & 0 deletions packages/lab/src/Comments/CommentComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ async function settle() {
}

describe('CommentComposer', () => {
it("calls the caller's onClick and lets the click bubble", () => {
const onClick = vi.fn();
const onAncestorClick = vi.fn();
render(
<div onClick={onAncestorClick}>
<CommentComposer
value=""
onChange={vi.fn()}
onSubmit={vi.fn()}
onClick={onClick}
data-testid="composer"
/>
</div>,
);
fireEvent.click(screen.getByTestId('composer'));
expect(onClick).toHaveBeenCalledTimes(1);
expect(onAncestorClick).toHaveBeenCalledTimes(1);
});

it('posts the draft from Post, and never an empty one', async () => {
const onSubmit = vi.fn();
const {rerender} = render(
Expand Down
19 changes: 15 additions & 4 deletions packages/lab/src/Comments/CommentComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,14 @@ export function CommentComposerBase({
</VStack>
);

const {xstyle, className, style, ...restRootProps} = rootProps ?? {};
const {
xstyle,
className,
style,
onClick: onRootClick,
...restRootProps
} = rootProps ?? {};
const isInThread = context.kind !== 'comment';
return (
<VStack
ref={rootRef}
Expand All @@ -583,9 +590,13 @@ export function CommentComposerBase({
style,
)}
onClick={event => {
// The composer keeps its clicks: in a thread, a press on its empty
// space would otherwise reach the thread and collapse it.
event.stopPropagation();
onRootClick?.(event);
// Inside a thread, the click stays in the composer. A press on a
// reply composer's empty space would otherwise reach the thread and
// collapse it.
Comment on lines +594 to +596

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the first sentence restates if (isInThread) event.stopPropagation() below it. The reason alone is enough:

// A press on a reply composer's empty space would otherwise reach the thread
// and collapse it.

if (isInThread) {
event.stopPropagation();
}
const target = event.target as Element;
if (
target.closest(COMPOSER_CONTROL_SELECTOR) == null &&
Expand Down
22 changes: 22 additions & 0 deletions packages/lab/src/Comments/CommentThread.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ describe('CommentThread', () => {
).toBeTruthy();
});

it('stays open on a press in the empty space of its reply composer', async () => {
const onSelectedChange = vi.fn();
render(
<CommentThread
comment={THREAD}
currentUser={VIEWER}
onSubmit={vi.fn()}
onSelectedChange={onSelectedChange}
/>,
);
fireEvent.click(screen.getByRole('button', {name: 'Thread by Maya Chen'}));
await settle();
const composer = document.querySelector('.astryx-comment-composer');
expect(composer).not.toBeNull();
fireEvent.click(composer!);
await settle();
expect(onSelectedChange).not.toHaveBeenCalledWith(false);
expect(
screen.getByRole('textbox', {name: 'Reply to Maya Chen…'}),
).toBeTruthy();
});

it('opens when the host selects it', async () => {
const {rerender} = render(
<CommentThread
Expand Down
Loading