From 8fd9c1ed887c6740248cff8b2eb3c52402419649 Mon Sep 17 00:00:00 2001 From: Jean-Marc Millet Date: Wed, 3 Jul 2024 15:20:48 +0200 Subject: [PATCH] remove defaultValue prop, update stories and delete corresponding test --- .../selectv2/Selectv2.component.tsx | 9 ------- src/lib/components/selectv2/selectv2.test.tsx | 9 ------- stories/Select/selectv2.stories.tsx | 27 +++++++------------ 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/lib/components/selectv2/Selectv2.component.tsx b/src/lib/components/selectv2/Selectv2.component.tsx index a84cd33e30..f3ca549b6c 100644 --- a/src/lib/components/selectv2/Selectv2.component.tsx +++ b/src/lib/components/selectv2/Selectv2.component.tsx @@ -302,7 +302,6 @@ export type SelectProps = { placeholder?: string; disabled?: boolean; children?: React.ReactNode; - defaultValue?: string; value?: string; onFocus?: (event: FocusEvent) => void; onBlur?: (event: FocusEvent) => void; @@ -357,7 +356,6 @@ function SelectWithOptionContext(props: SelectProps) { function SelectBox({ placeholder = 'Select...', disabled = false, - defaultValue, value, onChange, variant = 'default', @@ -366,11 +364,6 @@ function SelectBox({ id, ...rest }: SelectProps) { - if (defaultValue && value) { - console.error( - 'The `defaultValue` will be overridden by the `value` if they are set at the same time.', - ); - } const [keyboardFocusEnabled, setKeyboardFocusEnabled] = useState(false); const [searchSelection, setSearchSelection] = useState(''); const [searchValue, setSearchValue] = useState(''); @@ -414,7 +407,6 @@ function SelectBox({ // Force to reset the value useEffect(() => { if ( - !defaultValue && !isEmptyStringInOptions && value === '' && selectRef.current && @@ -436,7 +428,6 @@ function SelectBox({ value={ searchSelection || options.find((opt) => opt.value === value) } - defaultValue={defaultValue} inputValue={options.length > NOPT_SEARCH ? searchValue : undefined} selectedOption={options.find((opt) => opt.value === value)} keyboardFocusEnabled={keyboardFocusEnabled} diff --git a/src/lib/components/selectv2/selectv2.test.tsx b/src/lib/components/selectv2/selectv2.test.tsx index ff81d9ee5a..7c63d737a0 100644 --- a/src/lib/components/selectv2/selectv2.test.tsx +++ b/src/lib/components/selectv2/selectv2.test.tsx @@ -146,15 +146,6 @@ describe('SelectV2', () => { expect(screen.getByText(placeholder)).toBeInTheDocument(); }); - // This test is failing as Select is not working as expected - // TODO Work on Select component to display default value when it is defined and value is not - it('should display default value', () => { - const defaultUser = users[0]; - render(); - const select = selectors.select(); - expect(select).toHaveTextContent(defaultUser.label); - }); - it('should be disabled', () => { render(); // select input instead of select as disabled attribute is on input diff --git a/stories/Select/selectv2.stories.tsx b/stories/Select/selectv2.stories.tsx index 186175416f..871e0881c8 100644 --- a/stories/Select/selectv2.stories.tsx +++ b/stories/Select/selectv2.stories.tsx @@ -11,9 +11,9 @@ type SelectStory = StoryObj; const meta: Meta = { title: 'Components/Inputs/Select', component: Select, - decorators: [ - (story) => {story()}, - ], + // decorators: [ + // (story) => {story()}, + // ], }; export default meta; @@ -38,7 +38,7 @@ const generateOptions = (n = 10) => const optionsWithSearchBar = generateOptions(25); const optionsWithoutSearchBar = generateOptions(7); -const defaultOptions = generateOptions(4); +const defaultOptions = generateOptions(5); const thousandsOfOptions = generateOptions(1000); const optionsWithDisabledWithoutMessage = optionsWithSearchBar.map( (option, index) => { @@ -79,7 +79,6 @@ export const WithoutOptions: SelectStory = { export const DisabledSelect: SelectStory = { args: { disabled: true, - defaultValue: defaultOptions[0].props.value, children: defaultOptions, }, }; @@ -173,22 +172,16 @@ export const WithDefaultValue: SelectStory = { render: (args) => { const [{ value }, updateArgs] = useArgs(); return ( -
- - -

Selected value

-

{value}

-
+ ); }, args: { - value: undefined, + value: defaultOptions[0].props.value, placeholder: 'Select an option', children: defaultOptions, - defaultValue: defaultOptions[0].props.value, }, };