Skip to content

Commit

Permalink
remove defaultValue prop, update stories and delete corresponding test
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarcMilletScality committed Jul 3, 2024
1 parent 136d02f commit 8fd9c1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
9 changes: 0 additions & 9 deletions src/lib/components/selectv2/Selectv2.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -357,7 +356,6 @@ function SelectWithOptionContext(props: SelectProps) {
function SelectBox({
placeholder = 'Select...',
disabled = false,
defaultValue,
value,
onChange,
variant = 'default',
Expand All @@ -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('');
Expand Down Expand Up @@ -414,7 +407,6 @@ function SelectBox({
// Force to reset the value
useEffect(() => {
if (
!defaultValue &&
!isEmptyStringInOptions &&
value === '' &&
selectRef.current &&
Expand All @@ -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}
Expand Down
9 changes: 0 additions & 9 deletions src/lib/components/selectv2/selectv2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<SelectWrapper defaultValue={defaultUser.value} />);
const select = selectors.select();
expect(select).toHaveTextContent(defaultUser.label);
});

it('should be disabled', () => {
render(<SelectWrapper disabled />);
// select input instead of select as disabled attribute is on input
Expand Down
27 changes: 10 additions & 17 deletions stories/Select/selectv2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type SelectStory = StoryObj<typeof Select>;
const meta: Meta<typeof Select> = {
title: 'Components/Inputs/Select',
component: Select,
decorators: [
(story) => <Wrapper style={{ minHeight: '15rem' }}>{story()}</Wrapper>,
],
// decorators: [
// (story) => <Wrapper style={{ minHeight: '15rem' }}>{story()}</Wrapper>,
// ],
};

export default meta;
Expand All @@ -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) => {
Expand Down Expand Up @@ -79,7 +79,6 @@ export const WithoutOptions: SelectStory = {
export const DisabledSelect: SelectStory = {
args: {
disabled: true,
defaultValue: defaultOptions[0].props.value,
children: defaultOptions,
},
};
Expand Down Expand Up @@ -173,22 +172,16 @@ export const WithDefaultValue: SelectStory = {
render: (args) => {
const [{ value }, updateArgs] = useArgs();
return (
<div>
<Select
{...args}
onChange={(value) => updateArgs({ value })}
value={value}
></Select>

<h2>Selected value</h2>
<p>{value}</p>
</div>
<Select
{...args}
onChange={(value) => updateArgs({ value })}
value={value}
></Select>
);
},
args: {
value: undefined,
value: defaultOptions[0].props.value,
placeholder: 'Select an option',
children: defaultOptions,
defaultValue: defaultOptions[0].props.value,
},
};

0 comments on commit 8fd9c1e

Please sign in to comment.