diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.stories.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.stories.tsx index 5dffa4b7ea..38ae5d7c87 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.stories.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.stories.tsx @@ -47,6 +47,15 @@ export const WithHint: Story = { } }; +export const WithDefaultSelectedOption: Story = { + args: { + title: 'Title', + options: dropdownOptions, + defaultSelectedOption: 'option-3', + hint: 'Here\'s some hint' + } +}; + export const Error: Story = { args: { title: 'Title', diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.tsx index f7371f01c2..397ac6c6bf 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/Dropdown.tsx @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import Heading from './Heading'; import Hint from './Hint'; @@ -14,11 +14,18 @@ interface DropdownProps { onSelect: (value: string) => void; error?:boolean; hint?: React.ReactNode; + defaultSelectedOption?: string; } -const Dropdown: React.FC = ({title, options, onSelect, error, hint}) => { +const Dropdown: React.FC = ({title, options, onSelect, error, hint, defaultSelectedOption}) => { const [selectedOption, setSelectedOption] = useState(''); + useEffect(() => { + if (defaultSelectedOption) { + setSelectedOption(defaultSelectedOption); + } + }, [defaultSelectedOption]); + const handleOptionChange = (event: React.ChangeEvent) => { const selectedValue = event.target.value; setSelectedOption(selectedValue);