Skip to content

Commit e468024

Browse files
committed
refactor: Move listbox list prop types into the listbox folder
ListElementProps (formerly MenuProps) and GetOptionProps now live in src/internal/components/listbox/interfaces.ts. PlainList imports them from there, so the shared list no longer depends on Select's hook module. No behavior change.
1 parent 33cfa99 commit e468024

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
5+
import { DropdownOption } from '../option/interfaces';
6+
import { OptionsListProps } from '../options-list';
7+
import { ItemProps } from './parts/item';
8+
9+
/** Props spread onto the list element (`OptionsList`). */
10+
export type ListElementProps = Omit<OptionsListProps, 'children'> & { ref: React.RefObject<HTMLDivElement> };
11+
12+
/** Props for the row at `index`. */
13+
export type GetOptionProps = (option: DropdownOption, index: number) => ItemProps;

‎src/internal/components/listbox/parts/plain-list.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { useMergeRefs, useUniqueId } from '@cloudscape-design/component-toolkit/
77

88
import { MultiselectProps } from '../../../../multiselect/interfaces';
99
import { SelectProps } from '../../../../select/interfaces';
10-
import { GetOptionProps, MenuProps } from '../../../../select/utils/use-select';
1110
import { DropdownOption } from '../../option/interfaces';
1211
import OptionsList from '../../options-list';
1312
import { HighlightType } from '../../options-list/utils/use-highlight-option';
13+
import { GetOptionProps, ListElementProps } from '../interfaces';
1414
import { SelectionType } from '../selection/interfaces';
1515
import { fallbackItemHeight } from './common';
1616
import { renderOptions } from './render-options';
@@ -19,7 +19,7 @@ import scrollToIndex from './scroll-to-index';
1919
import styles from '../../../../select/parts/styles.css.js';
2020

2121
export interface SelectListProps {
22-
menuProps: MenuProps;
22+
menuProps: ListElementProps;
2323
getOptionProps: GetOptionProps;
2424
filteredOptions: ReadonlyArray<DropdownOption>;
2525
filteringValue: string;

‎src/select/utils/use-select.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useUniqueId } from '@cloudscape-design/component-toolkit/internal';
77

88
import { InternalDropdownProps } from '../../dropdown/internal';
99
import { ButtonTriggerProps } from '../../internal/components/button-trigger';
10-
import { ItemProps } from '../../internal/components/listbox/parts/item';
10+
import { ListElementProps } from '../../internal/components/listbox/interfaces';
1111
import { SelectionModel } from '../../internal/components/listbox/selection/interfaces';
1212
import { singleSelection } from '../../internal/components/listbox/selection/single-selection';
1313
import { connectOptionsByValue } from '../../internal/components/listbox/utils/connect-options';
@@ -21,7 +21,6 @@ import {
2121
} from '../../internal/components/listbox/utils/option-props';
2222
import { DropdownOption } from '../../internal/components/option/interfaces';
2323
import { isGroupInteractive, isInteractive } from '../../internal/components/option/utils/filter-options';
24-
import { OptionsListProps } from '../../internal/components/options-list';
2524
import { useHighlightedOption } from '../../internal/components/options-list/utils/use-highlight-option';
2625
import { getOptionId } from '../../internal/components/options-list/utils/use-ids';
2726
import { useMenuKeyboard, useTriggerKeyboard } from '../../internal/components/options-list/utils/use-keyboard';
@@ -35,9 +34,6 @@ import { OptionDefinition } from '../../types/option';
3534
import { SelectProps } from '../interfaces';
3635
import { FilterProps } from '../parts/filter';
3736

38-
export type MenuProps = Omit<OptionsListProps, 'children'> & { ref: React.RefObject<HTMLDivElement> };
39-
export type GetOptionProps = (option: DropdownOption, index: number) => ItemProps;
40-
4137
interface UseSelectProps {
4238
selectedOptions: ReadonlyArray<OptionDefinition>;
4339
updateSelectedOption: (option: OptionDefinition) => void;
@@ -231,7 +227,7 @@ export function useSelect({
231227
};
232228

233229
const getMenuProps = () => {
234-
const menuProps: MenuProps = {
230+
const menuProps: ListElementProps = {
235231
id: menuId,
236232
ref: menuRef,
237233
open: isOpen,

0 commit comments

Comments
 (0)