Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(lab): a busy comment editor's Cancel link stays in the tab order (#7909)

Cindy Zhang02f5fe490d39
diff --git a/apps/storybook/stories/Comments.stories.tsx b/apps/storybook/stories/Comments.stories.tsx
index bf51838f1b..63e5fb068f 100644
--- a/apps/storybook/stories/Comments.stories.tsx
+++ b/apps/storybook/stories/Comments.stories.tsx
@@ -256,6 +256,21 @@ export const Narrow: Story = {
),
};
+/** Saving an edit that has not finished: the editor stays busy. */
+export const SavingAnEdit: Story = {
+ render: () => (
+ <VStack width={480} height={520}>
+ <Comments
+ comments={COMMENTS}
+ currentUser={VIEWER}
+ onSubmit={() => {}}
+ onSaveEdit={() => new Promise<void>(() => {})}
+ onDelete={() => {}}
+ />
+ </VStack>
+ ),
+};
+
/** Embedded at its content height inside a popover: no scroll area or dock. */
export const EmbeddedInAPopover: Story = {
render: () => (
diff --git a/packages/lab/src/Comments/CommentComposer.test.tsx b/packages/lab/src/Comments/CommentComposer.test.tsx
index e5287b606c..1dbc7d5f4e 100644
--- a/packages/lab/src/Comments/CommentComposer.test.tsx
+++ b/packages/lab/src/Comments/CommentComposer.test.tsx
@@ -25,7 +25,7 @@ vi.mock('../EmojiPicker/emojiData', () => ({
],
}));
-import {CommentComposer} from './CommentComposer';
+import {CommentComposer, CommentComposerBase} from './CommentComposer';
const originalMatches = HTMLElement.prototype.matches;
const popoverOpenState = new WeakMap<HTMLElement, boolean>();
@@ -101,6 +101,34 @@ describe('CommentComposer', () => {
expect(onSubmit).toHaveBeenCalledWith('Looks good');
});
+ it('keeps Cancel in the tab order but inert while submitting (AST-085 FR1, FR2)', () => {
+ const onCancel = vi.fn();
+ render(
+ <CommentComposerBase
+ value="Draft"
+ onChange={() => {}}
+ onSubmit={() => {}}
+ placeholder="Edit comment"
+ onCancel={onCancel}
+ context={{kind: 'edit', commentId: 'c1'}}
+ contextLabel="Editing comment"
+ highlightColor="yellow"
+ triggers={[]}
+ agentCommands={[]}
+ hasEmojiPicker={false}
+ isSubmitting
+ />,
+ );
+ const cancel = screen.getByText('Cancel').closest('a, button')!;
+ expect(cancel).toHaveAttribute('aria-disabled', 'true');
+ expect(cancel).not.toHaveAttribute('tabindex', '-1');
+ act(() => (cancel as HTMLElement).focus());
+ expect(cancel).toHaveFocus();
+ fireEvent.click(cancel);
+ fireEvent.keyDown(cancel, {key: 'Enter'});
+ expect(onCancel).not.toHaveBeenCalled();
+ });
+
it('shows the placeholder as the input’s name, and keeps Post focusable while submitting', () => {
const onSubmit = vi.fn();
const {container} = render(
diff --git a/packages/lab/src/Comments/CommentParts.tsx b/packages/lab/src/Comments/CommentParts.tsx
index 6fd49cd78d..bbeb08c5b9 100644
--- a/packages/lab/src/Comments/CommentParts.tsx
+++ b/packages/lab/src/Comments/CommentParts.tsx
@@ -382,8 +382,8 @@ export function MetadataActionLink({
color="secondary"
xstyle={partStyles.noWrap}
data-metadata-action={actionRole}
- aria-disabled={isDisabled || undefined}
- tabIndex={isDisabled ? -1 : undefined}
+ // Link keeps a disabled link in the tab order (spec:AST-085 FR1).
+ isDisabled={isDisabled}
onClick={event => {
event.preventDefault();
if (isDisabled !== true) {
@@ -725,10 +725,7 @@ export function HistoryDialog({
content={
<LayoutContent>
{history.isLoading ? (
- <Spinner
- size="lg"
- label={t('@astryx.comments.historyLoading')}
- />
+ <Spinner size="lg" label={t('@astryx.comments.historyLoading')} />
) : history.error != null ? (
<Banner
status="error"