diff --git a/apps/site/components/Downloads/Release/InstallationMethodDropdown.tsx b/apps/site/components/Downloads/Release/InstallationMethodDropdown.tsx index cb181ba20448a..4cc89b2149d2a 100644 --- a/apps/site/components/Downloads/Release/InstallationMethodDropdown.tsx +++ b/apps/site/components/Downloads/Release/InstallationMethodDropdown.tsx @@ -76,7 +76,7 @@ const InstallationMethodDropdown: FC = () => { return ( values={grouppedMethods} - defaultValue={release.installMethod} + value={release.installMethod} loading={release.os === 'LOADING' || release.installMethod === ''} ariaLabel={t('layouts.download.dropdown.platform')} onChange={platform => platform && release.setInstallMethod(platform)} diff --git a/apps/site/components/Downloads/Release/OperatingSystemDropdown.tsx b/apps/site/components/Downloads/Release/OperatingSystemDropdown.tsx index c3630cc719e5d..b559a7b046373 100644 --- a/apps/site/components/Downloads/Release/OperatingSystemDropdown.tsx +++ b/apps/site/components/Downloads/Release/OperatingSystemDropdown.tsx @@ -52,7 +52,7 @@ const OperatingSystemDropdown: FC = () => { return ( values={parsedOperatingSystems} - defaultValue={release.os !== 'LOADING' ? release.os : undefined} + value={release.os !== 'LOADING' ? release.os : undefined} loading={release.os === 'LOADING'} placeholder={t('layouts.download.dropdown.unknown')} ariaLabel={t('layouts.download.dropdown.os')} diff --git a/apps/site/components/Downloads/Release/PackageManagerDropdown.tsx b/apps/site/components/Downloads/Release/PackageManagerDropdown.tsx index ec1bcb4a82417..8915c29d0dbb8 100644 --- a/apps/site/components/Downloads/Release/PackageManagerDropdown.tsx +++ b/apps/site/components/Downloads/Release/PackageManagerDropdown.tsx @@ -37,7 +37,7 @@ const PackageManagerDropdown: FC = () => { return ( values={parsedPackageManagers} - defaultValue={release.packageManager} + value={release.packageManager} loading={release.os === 'LOADING' || release.installMethod === ''} ariaLabel={t('layouts.download.dropdown.packageManager')} onChange={manager => release.setPackageManager(manager)} diff --git a/apps/site/components/Downloads/Release/PlatformDropdown.tsx b/apps/site/components/Downloads/Release/PlatformDropdown.tsx index 3d5b4e65eb72d..8092c7bcf0863 100644 --- a/apps/site/components/Downloads/Release/PlatformDropdown.tsx +++ b/apps/site/components/Downloads/Release/PlatformDropdown.tsx @@ -60,7 +60,7 @@ const PlatformDropdown: FC = () => { return ( values={parsedPlatforms} - defaultValue={release.platform !== '' ? release.platform : undefined} + value={release.platform !== '' ? release.platform : undefined} loading={release.os === 'LOADING' || release.platform === ''} placeholder={t('layouts.download.dropdown.unknown')} ariaLabel={t('layouts.download.dropdown.platform')} diff --git a/packages/ui-components/src/Common/Select/NoScriptSelect/index.tsx b/packages/ui-components/src/Common/Select/NoScriptSelect/index.tsx index 1884c8c5e6f27..bb2cfde0f676d 100644 --- a/packages/ui-components/src/Common/Select/NoScriptSelect/index.tsx +++ b/packages/ui-components/src/Common/Select/NoScriptSelect/index.tsx @@ -7,6 +7,7 @@ import type { StatelessSelectProps } from '#ui/Common/Select/StatelessSelect'; const WithNoScriptSelect = ({ as, + defaultValue, ...props }: StatelessSelectProps) => { const id = useId(); @@ -14,10 +15,10 @@ const WithNoScriptSelect = ({ return ( <> - ); diff --git a/packages/ui-components/src/Common/Select/StatelessSelect/index.tsx b/packages/ui-components/src/Common/Select/StatelessSelect/index.tsx index 063cb1033b7e2..514597651b7e4 100644 --- a/packages/ui-components/src/Common/Select/StatelessSelect/index.tsx +++ b/packages/ui-components/src/Common/Select/StatelessSelect/index.tsx @@ -13,8 +13,10 @@ type StatelessSelectConfig = { as?: LinkLike | 'div'; }; -export type StatelessSelectProps = SelectProps & - StatelessSelectConfig; +export type StatelessSelectProps = Omit, 'value'> & + StatelessSelectConfig & { + defaultValue?: T; + }; const StatelessSelect = ({ values = [], diff --git a/packages/ui-components/src/Common/Select/index.stories.tsx b/packages/ui-components/src/Common/Select/index.stories.tsx index 28585ceb4dcfc..4210738d96e10 100644 --- a/packages/ui-components/src/Common/Select/index.stories.tsx +++ b/packages/ui-components/src/Common/Select/index.stories.tsx @@ -1,3 +1,5 @@ +import { useArgs } from 'storybook/preview-api'; + import Select from '#ui/Common/Select'; import StatelessSelect from '#ui/Common/Select/StatelessSelect'; import * as OSIcons from '#ui/Icons/OperatingSystem'; @@ -10,7 +12,7 @@ type Meta = MetaObj; export const Default: Story = { args: { values: ['v20.8.0', 'v19.9.0', 'v18.18.0', 'v17.9.1', 'v16.20.2'], - defaultValue: 'v16.20.2', + value: 'v16.20.2', label: 'Node.js version', }, }; @@ -18,14 +20,14 @@ export const Default: Story = { export const WithoutLabel: Story = { args: { values: ['v20.8.0', 'v19.9.0', 'v18.18.0', 'v17.9.1', 'v16.20.2'], - defaultValue: 'v16.20.2', + value: 'v16.20.2', }, }; export const WithScrollButtons: Story = { args: { values: Array.from({ length: 100 }, (_, i) => `Item ${i}`), - defaultValue: 'Item 50', + value: 'Item 50', }, }; @@ -35,14 +37,8 @@ export const DropdownLabel: Story = { { label: 'Getting Started', items: [ - { - value: 'section-1', - label: 'Getting Started', - }, - { - value: 'section-2', - label: 'How to install Node.js', - }, + { value: 'section-1', label: 'Getting Started' }, + { value: 'section-2', label: 'How to install Node.js' }, { value: 'section-3', label: 'How much JavaScript do you need to know to use Node.js?', @@ -51,18 +47,12 @@ export const DropdownLabel: Story = { value: 'section-4', label: 'Differences between Node.js and the Browser', }, - { - value: 'section-5', - label: 'The V8 JavaScript Engine', - }, + { value: 'section-5', label: 'The V8 JavaScript Engine' }, { value: 'section-6', label: 'An introduction to the npm package manager', }, - { - value: 'section-7', - label: 'ECMAScript 2015 (ES6) and beyond', - }, + { value: 'section-7', label: 'ECMAScript 2015 (ES6) and beyond' }, { value: 'section-8', label: 'Node.js, the difference between development and production', @@ -104,7 +94,7 @@ export const InlineSelect: Story = { ], }, ], - defaultValue: 'macos', + value: 'macos', inline: true, }, }; @@ -118,4 +108,16 @@ export const WithNoScriptSelect: Story = { ), }; -export default { component: Select } as Meta; +export default { + component: Select, + render: (args) => { + const [, setArgs] = useArgs(); + + const onChange = (value: string) => { + args.onChange?.(value); + setArgs({ value }); + }; + + return