Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a5816e7
feat: Add OptionList component
amanabiy Oct 22, 2026
b8992c3
fix: Prevent native page scroll on Home and End in OptionList
amanabiy Oct 26, 2026
789fe5f
chore: Clean up OptionList tests and dev pages
amanabiy Oct 26, 2026
69c5809
fix: Use own i18n namespace in OptionList
amanabiy Oct 26, 2026
8759506
test: Cover OptionList disabled reason tooltip Escape
amanabiy Oct 26, 2026
28ad595
chore: Use page templates for OptionList dev pages
amanabiy Oct 26, 2026
3c889b6
test: Drop duplicate root scroll container from OptionList scroll page
amanabiy Oct 26, 2026
62a031a
feat: Add OptionList renderOption item types
amanabiy Oct 27, 2026
fe813fa
fix: Ignore non-matching group headers in OptionList type-ahead
amanabiy Oct 27, 2026
fde3009
fix: Ignore handled keys in OptionList type-ahead
amanabiy Oct 27, 2026
f8188ea
chore: add settings to make it easier to test
amanabiy Oct 27, 2026
4a2e5c9
fix: Pass the group state as parent in OptionList renderOption
amanabiy Oct 27, 2026
4cc5253
fix: Keep disabled reason description with custom OptionList options
amanabiy Oct 28, 2026
8aa783f
fix: Scroll OptionList highlight on repeated keyboard navigation
amanabiy Oct 28, 2026
fd8244d
fix: Keep OptionList highlight in sync when options change
amanabiy Oct 28, 2026
e8e80e4
fix: Wrap OptionList arrow keys at the first and last highlightable o…
amanabiy Oct 28, 2026
f62ff01
fix: Start OptionList keyboard focus on the selected option despite h…
amanabiy Oct 28, 2026
a789ffb
fix: Require option values in OptionList
amanabiy Oct 28, 2026
083f614
feat: Add renderHighlightedAriaLive to OptionList
amanabiy Oct 28, 2026
3d9eddd
fix: Skip OptionList scroll when nothing is highlighted
amanabiy Oct 28, 2026
a8f6dc0
test: Split OptionList unit tests by feature
amanabiy Oct 28, 2026
a212bfc
test: Prune redundant OptionList unit tests
amanabiy Oct 28, 2026
4925c40
test: Remove OptionList tests covered by listbox tests
amanabiy Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-tools/utils/pluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const pluralizationMap = {
Modal: 'Modals',
Multiselect: 'Multiselects',
NavigableGroup: 'NavigableGroups',
OptionList: 'OptionLists',
Pagination: 'Paginations',
AppLayoutToolbar: 'AppLayoutToolbars',
PanelLayout: 'PanelLayouts',
Expand Down
29 changes: 29 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ export default tsEslint.config(
],
},
},
{
// OptionList and the shared listbox engine sit below Select and Multiselect, so they must not depend on them at
// runtime. Type-only imports (e.g. the `renderOption` types) are allowed. The remaining listbox files join this
// rule when Select and Multiselect move onto the engine.
files: [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this rule still needed?

'src/option-list/**',
'src/internal/components/listbox/use-listbox.ts',
'src/internal/components/listbox/use-type-ahead.ts',
'src/internal/components/listbox/index.tsx',
'src/internal/components/listbox/parts/list.tsx',
'src/internal/components/listbox/parts/item.tsx',
],
ignores: ['**/__tests__/**', '**/__integ__/**', '**/__motion__/**', '**/__a11y__/**'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/select/**', '**/multiselect/**'],
allowTypeImports: true,
message:
'OptionList and the listbox engine sit below Select and Multiselect. Import only types from them, or move the shared code down.',
},
],
},
],
},
},
{
files: ['**/__tests__/**', '**/__integ__/**', '**/__motion__/**', '**/__a11y__/**'],
...jestPlugin.configs['flat/recommended'],
Expand Down
65 changes: 65 additions & 0 deletions pages/option-list/permutations.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The permutations page is very long and can exceed our limit if a more cases are added. I recommend to split it in two pages, e.g. permutations-single and permutations-multi.

// SPDX-License-Identifier: Apache-2.0
import React from 'react';

import Icon from '~components/icon';
import OptionList, { OptionListProps } from '~components/option-list';

import { PermutationsPage } from '../app/templates';
import createPermutations from '../utils/permutations';
import PermutationsView from '../utils/permutations-view';

const plain: OptionListProps.Option[] = [
{ value: '1', label: 'Reduce cost' },
{ value: '2', label: 'Improve performance', description: 'Prioritize latency and throughput.' },
{
value: '3',
label: 'Increase reliability across every Region and Availability Zone that hosts the workload',
description: 'A long label and a long description that wrap onto multiple lines on narrow containers.',
},
{ value: '4', label: 'Strengthen security' },
];
const withIcons = plain.map(option => ({ ...option, icon: <Icon name="settings" /> }));
const withTags = plain.map(option => ({ ...option, labelTag: '128 GB', tags: ['CPU-v2', '2 GB RAM'] }));
const withDisabled = plain.map(option =>
option.value === '2' || option.value === '4'
? { ...option, disabled: true, disabledReason: option.value === '4' ? 'Requires Enterprise support' : undefined }
: option
);
const grouped: OptionListProps.Options = [
{ value: 'group-1', label: 'Goals', options: plain.slice(0, 2) },
{ value: 'group-2', label: 'More goals', options: plain.slice(2) },
];

const renderOption: OptionListProps['renderOption'] = ({ item }) => <strong>{item.option.label}</strong>;

const permutations = createPermutations<OptionListProps & { width: number }>([
{
width: [240, 480],
options: [plain, withIcons, withTags, withDisabled, grouped],
selectionType: ['single', 'multi'],
selectedOptions: [[], [plain[1]], [plain[1], plain[2]]],
},
{
width: [240],
options: [grouped],
selectionType: ['single', 'multi'],
selectedOptions: [[plain[1]]],
renderOption: [renderOption],
},
]).filter(({ selectionType, selectedOptions }) => selectionType === 'multi' || (selectedOptions?.length ?? 0) < 2);

export default function OptionListPermutationsPage() {
return (
<PermutationsPage title="OptionList permutations" screenshotArea={{ disableAnimations: true }}>
<PermutationsView
permutations={permutations}
render={({ width, ...props }) => (
<div style={{ inlineSize: width }}>
<OptionList {...props} ariaLabel="Goals" onChange={() => {}} />
</div>
)}
/>
</PermutationsPage>
);
}
216 changes: 216 additions & 0 deletions pages/option-list/scroll.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useContext, useEffect, useRef, useState } from 'react';

import Button, { ButtonProps } from '~components/button';
import Dropdown from '~components/dropdown';
import FormField from '~components/form-field';
import Header from '~components/header';
import OptionList, { OptionListProps } from '~components/option-list';
import SegmentedControl from '~components/segmented-control';
import SpaceBetween from '~components/space-between';

import AppContext, { AppContextType } from '../app/app-context';
import { SimplePage } from '../app/templates';

import styles from './scroll.scss';

/**
* Where the scrolling happens:
* - `wrapper`: a wrapper div with a fixed height and `overflow: auto`.
* - `page`: no container, the page scrolls.
* - `dropdown`: the list is the content of a Dropdown opened by a button.
*/
type Container = 'wrapper' | 'page' | 'dropdown';
type Preselected = 'none' | 'near-end';

type PageContext = React.Context<
AppContextType<{
container?: Container;
expandToViewport?: boolean;
selectionType?: OptionListProps.SelectionType;
preselected?: Preselected;
}>
>;

const options: OptionListProps.Option[] = Array.from({ length: 100 }, (_, index) => ({
value: `option-${index + 1}`,
label: `Option ${index + 1}`,
}));

function DropdownOptionList({
expandToViewport,
list,
listRef,
}: {
expandToViewport: boolean;
list: (props: { onChange: () => void }) => React.ReactNode;
listRef: React.RefObject<OptionListProps.Ref>;
}) {
const [open, setOpen] = useState(false);
const triggerRef = useRef<ButtonProps.Ref>(null);

// Move focus into the list once the Dropdown has rendered its content.
useEffect(() => {
if (open) {
listRef.current?.focus();
}
}, [open, listRef]);

const close = (returnFocus: boolean) => {
setOpen(false);
if (returnFocus) {
triggerRef.current?.focus();
}
};

return (
<Dropdown
open={open}
onOutsideClick={() => close(false)}
onEscape={() => close(true)}
minWidth={320}
expandToViewport={expandToViewport}
trigger={
<Button
id="dropdown-trigger"
ref={triggerRef}
ariaExpanded={open}
ariaHaspopup="listbox"
iconName="caret-down-filled"
iconAlign="right"
onClick={() => setOpen(!open)}
>
Choose an option
</Button>
}
content={<div className={styles['dropdown-content']}>{list({ onChange: () => close(true) })}</div>}
/>
);
}

function ConfiguredOptionList({
container,
expandToViewport,
selectionType,
preselected,
}: {
container: Container;
expandToViewport: boolean;
selectionType: OptionListProps.SelectionType;
preselected: Preselected;
}) {
const [selectedOptions, setSelectedOptions] = useState<ReadonlyArray<OptionListProps.Option>>(
preselected === 'near-end' ? [options[80]] : []
);
const listRef = useRef<OptionListProps.Ref>(null);

const list = ({ onChange }: { onChange?: () => void } = {}) => (
<OptionList
ref={listRef}
data-testid="option-list"
ariaLabelledby="option-list-heading"
selectionType={selectionType}
options={options}
selectedOptions={selectedOptions}
onChange={({ detail }) => {
setSelectedOptions(detail.selectedOptions);
onChange?.();
}}
/>
);

return (
<SpaceBetween size="xs">
{/* Integ tests click the heading, then press Tab to move keyboard focus into the list. */}
<Header variant="h2" id="option-list-heading">
Long list
</Header>
{container === 'wrapper' && (
<div id="scroll-container" className={styles['fixed-height']}>
{list()}
</div>
)}
{container === 'page' && list()}
{container === 'dropdown' && (
<DropdownOptionList expandToViewport={expandToViewport} list={list} listRef={listRef} />
)}
<div data-testid="selected-value">
Selected: {selectedOptions.map(option => option.value).join(', ') || 'none'}
</div>
</SpaceBetween>
);
}

export default function OptionListScrollPage() {
const { urlParams, setUrlParams } = useContext(AppContext as PageContext);
const container = urlParams.container ?? 'wrapper';
const expandToViewport = urlParams.expandToViewport ?? false;
const selectionType = urlParams.selectionType ?? 'single';
const preselected = urlParams.preselected ?? 'none';

return (
<SimplePage
title="Option list: scrolling long lists"
settings={
<SpaceBetween size="m">
<FormField label="Scroll container">
<SegmentedControl
selectedId={container}
onChange={({ detail }) => setUrlParams({ container: detail.selectedId as Container })}
options={[
{ id: 'wrapper', text: 'Wrapper' },
{ id: 'page', text: 'Page' },
{ id: 'dropdown', text: 'Dropdown' },
]}
/>
</FormField>
<FormField label="Expand to viewport (Dropdown only)">
<SegmentedControl
selectedId={`${expandToViewport}`}
onChange={({ detail }) => setUrlParams({ expandToViewport: detail.selectedId === 'true' })}
options={[
{ id: 'false', text: 'No' },
{ id: 'true', text: 'Yes' },
]}
/>
</FormField>
<FormField label="Selection type">
<SegmentedControl
selectedId={selectionType}
onChange={({ detail }) =>
setUrlParams({ selectionType: detail.selectedId as OptionListProps.SelectionType })
}
options={[
{ id: 'single', text: 'Single' },
{ id: 'multi', text: 'Multi' },
]}
/>
</FormField>
<FormField label="Already selected">
<SegmentedControl
selectedId={preselected}
onChange={({ detail }) => setUrlParams({ preselected: detail.selectedId as Preselected })}
options={[
{ id: 'none', text: 'None' },
{ id: 'near-end', text: 'Option 81' },
]}
/>
</FormField>
</SpaceBetween>
}
screenshotArea={{}}
>
<div style={{ maxInlineSize: 520 }}>
{/* Remount on every configuration change so the initial selection follows the settings. */}
<ConfiguredOptionList
key={`${container}-${expandToViewport}-${selectionType}-${preselected}`}
container={container}
expandToViewport={expandToViewport}
selectionType={selectionType}
preselected={preselected}
/>
</div>
</SimplePage>
);
}
15 changes: 15 additions & 0 deletions pages/option-list/scroll.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// A scroll container for the list. Applied to a wrapper div.
.fixed-height {
block-size: 240px;
overflow: auto;
}

// Lets the list scroll inside the Dropdown content instead of overflowing it.
.dropdown-content {
overflow: auto;
}
Loading
Loading