Skip to content

Commit

Permalink
Update focus
Browse files Browse the repository at this point in the history
  • Loading branch information
timogasda committed Nov 2, 2023
1 parent 65f7eeb commit cd17ad9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 3 additions & 5 deletions pages/cards/selection.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import range from 'lodash/range';
import Cards, { CardsProps } from '~components/cards';
import Header from '~components/header';
import Toggle from '~components/toggle';
import { EmptyState } from '../table/shared-configs';
import { EmptyState, getMatchesCountText, paginationLabels } from '../table/shared-configs';
import { useCollection } from '@cloudscape-design/collection-hooks';
import Pagination from '~components/pagination';
import TextFilter from '~components/text-filter';
Expand Down Expand Up @@ -49,8 +49,6 @@ const cardDefinition: CardsProps.CardDefinition<Item> = {
],
};

const getTextFilterCounterText = (count: number) => `${count} ${count === 1 ? 'match' : 'matches'}`;

const allItems = createSimpleItems(50);

export default function () {
Expand Down Expand Up @@ -92,14 +90,14 @@ export default function () {
renderAriaLive={renderAriaLive}
entireCardClickable={entireCard}
isItemDisabled={item => someDisabled && !item.text.includes('o')}
pagination={<Pagination {...paginationProps} />}
pagination={<Pagination {...paginationProps} ariaLabels={paginationLabels} />}
filter={
<TextFilter
{...filterProps}
filteringAriaLabel="Filter resources"
filteringPlaceholder="Find resources"
filteringClearAriaLabel="Clear"
countText={getTextFilterCounterText(filteredItemsCount ?? 0)}
countText={getMatchesCountText(filteredItemsCount ?? 0)}
/>
}
/>
Expand Down
1 change: 1 addition & 0 deletions src/cards/__tests__/selection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Cards selection', () => {
).wrapper;
getCard(1).findCardHeader()?.click();
expectSelected([{ description: '1' }]);
expect(getCardSelectionArea(1)?.find('input')?.getElement()).toHaveFocus();
});
});

Expand Down
10 changes: 9 additions & 1 deletion src/cards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,15 @@ const CardsList = <T,>({
>
<div
className={styles['card-inner']}
onClick={canClickEntireCard ? getItemSelectionProps(item).onChange : undefined}
onClick={
canClickEntireCard
? event => {
getItemSelectionProps(item).onChange();
// Manually move focus to the native input (checkbox or radio button)
event.currentTarget.querySelector('input')?.focus();
}
: undefined
}
>
<div className={styles['card-header']}>
<div className={styles['card-header-inner']}>
Expand Down

0 comments on commit cd17ad9

Please sign in to comment.