diff --git a/pages/table-fragments/grid-navigation-custom.page.tsx b/pages/table-fragments/grid-navigation-custom.page.tsx index 46c55760e9..c564ea387b 100644 --- a/pages/table-fragments/grid-navigation-custom.page.tsx +++ b/pages/table-fragments/grid-navigation-custom.page.tsx @@ -7,6 +7,7 @@ import { AppLayout, Button, ButtonDropdown, + ButtonGroup, Checkbox, CollectionPreferences, ColumnLayout, @@ -60,13 +61,14 @@ type PageContext = React.Context< }> >; -type ActionsMode = 'dropdown' | 'inline'; +type ActionsMode = 'dropdown' | 'inline' | 'button-group'; const tableRoleOptions = [{ value: 'table' }, { value: 'grid' }, { value: 'grid-default' }]; const actionsModeOptions = [ { value: 'dropdown', label: 'Dropdown' }, - { value: 'inline', label: 'Inline (anti-pattern)' }, + { value: 'inline', label: 'Inline' }, + { value: 'button-group', label: 'Button group' }, ]; export default function Page() { @@ -458,19 +460,47 @@ function ItemActionsCell({ ); } - return ( -
-
- ); + if (mode === 'inline') { + return ( +
+
+ ); + } + if (mode === 'button-group') { + return ( +
+ { + switch (event.detail.id) { + case 'delete': + return onDelete(); + case 'duplicate': + return onDuplicate(); + case 'update': + return onUpdate(); + } + }} + /> +
+ ); + } + return null; } function DnsEditCell({ item }: { item: Instance }) { diff --git a/src/internal/context/__tests__/single-tab-stop-navigation-context.test.tsx b/src/internal/context/__tests__/single-tab-stop-navigation-context.test.tsx index 7f167aa7f9..c8d6440323 100644 --- a/src/internal/context/__tests__/single-tab-stop-navigation-context.test.tsx +++ b/src/internal/context/__tests__/single-tab-stop-navigation-context.test.tsx @@ -1,21 +1,59 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { useRef } from 'react'; +import React, { useContext, useEffect, useRef } from 'react'; import { render } from '@testing-library/react'; import { + SingleTabStopNavigationAPI, SingleTabStopNavigationContext, + SingleTabStopNavigationProvider, useSingleTabStopNavigation, } from '../../../../lib/components/internal/context/single-tab-stop-navigation-context'; import { renderWithSingleTabStopNavigation } from './utils'; +// Simple STSN subscriber component function Button(props: React.HTMLAttributes) { const buttonRef = useRef(null); const { tabIndex } = useSingleTabStopNavigation(buttonRef, { tabIndex: props.tabIndex }); return + + {children} + + + ); +} + +function findGroupButton(groupId: string, buttonIndex: number) { + return document.querySelector(`#${groupId}`)!.querySelectorAll('button')[buttonIndex] as HTMLElement; +} + test('does not override tab index when keyboard navigation is not active', () => { renderWithSingleTabStopNavigation(