Skip to content

Commit

Permalink
UI: fix keydown focusInInput check when input is in a shadow dom
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek committed Sep 12, 2023
1 parent 22bc762 commit 4be9ce5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,9 @@ describe('PreviewWeb', () => {
const preview = await createAndRenderPreview();

preview.onKeydown({
target: { tagName: 'div', getAttribute: jest.fn().mockReturnValue(null) },
composedPath: jest
.fn()
.mockReturnValue([{ tagName: 'div', getAttribute: jest.fn().mockReturnValue(null) }]),
} as any);

expect(mockChannel.emit).toHaveBeenCalledWith(PREVIEW_KEYDOWN, expect.objectContaining({}));
Expand All @@ -3514,7 +3516,9 @@ describe('PreviewWeb', () => {
const preview = await createAndRenderPreview();

preview.onKeydown({
target: { tagName: 'input', getAttribute: jest.fn().mockReturnValue(null) },
composedPath: jest
.fn()
.mockReturnValue([{ tagName: 'input', getAttribute: jest.fn().mockReturnValue(null) }]),
} as any);

expect(mockChannel.emit).not.toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import type { StorySpecifier } from '../store/StoryIndexStore';
const globalWindow = globalThis;

function focusInInput(event: Event) {
const target = event.target as Element;
const target = event.composedPath()[0] as Element;
return /input|textarea/i.test(target.tagName) || target.getAttribute('contenteditable') !== null;
}

Expand Down

0 comments on commit 4be9ce5

Please sign in to comment.