From 6c2cfb5c279be45ccb4e7f4719ae3a16aa5c370c Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Fri, 15 May 2026 11:16:32 +0200 Subject: [PATCH] fix: Focus lock uses correct direction when initial focus is outside the lock --- pages/focus-lock.page.tsx | 52 +++++++---- .../focus-lock/__tests__/focus-lock.test.tsx | 87 +++++++++++++++++-- src/internal/components/focus-lock/index.tsx | 6 +- 3 files changed, 121 insertions(+), 24 deletions(-) diff --git a/pages/focus-lock.page.tsx b/pages/focus-lock.page.tsx index ea0821ca57..b7436bbc2d 100644 --- a/pages/focus-lock.page.tsx +++ b/pages/focus-lock.page.tsx @@ -2,28 +2,48 @@ // SPDX-License-Identifier: Apache-2.0 import React, { useRef, useState } from 'react'; -import Box from '~components/box'; -import Button from '~components/button'; -import FormField from '~components/form-field'; -import Input from '~components/input'; +import { Button, FormField, Input, SpaceBetween, Tabs } from '~components'; import FocusLock, { FocusLockRef } from '~components/internal/components/focus-lock'; -import SpaceBetween from '~components/space-between'; + +import { SimplePage } from './app/templates'; export default function FocusLockPage() { const ref = useRef(null); const [text, setText] = useState(''); return ( - -

FocusLock component

- - - - setText(event.detail.value)} /> - - - - -
+ + + + + setText(event.detail.value)} /> + + + + + ), + }, + { + id: 'without-auto-focus', + label: 'Without auto focus', + content: ( + + + + + + + + ), + }, + ]} + /> + ); } diff --git a/src/internal/components/focus-lock/__tests__/focus-lock.test.tsx b/src/internal/components/focus-lock/__tests__/focus-lock.test.tsx index 39e33769c0..b89d51de65 100644 --- a/src/internal/components/focus-lock/__tests__/focus-lock.test.tsx +++ b/src/internal/components/focus-lock/__tests__/focus-lock.test.tsx @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import FocusLock, { FocusLockProps } from '../../../../../lib/components/internal/components/focus-lock'; @@ -9,12 +9,14 @@ type TestFixtureProps = Omit & { unmount?: boolean } function TestFixture({ unmount = false, ...props }: TestFixtureProps) { return ( <> -