28 Jun 2024 11:40 AM
Hi! Is it possible to combine clearable props with the setting state? It seems that pressing "clear selection" does not affect the state.
https://developer.dynatrace.com/reference/design-system/preview/forms/SelectV2/#control-the-state
Solved! Go to Solution.
28 Jun 2024 02:04 PM - edited 28 Jun 2024 02:04 PM
hi @veranika_k, what version of Strato are you using? I just tried the latest (0.114.3) and it works as expected (sets the value to null when the selection is cleared). Here's the code I used:
export const App = () => {
const [singleValue, setSingleValue] = useState<string | null>(null);
useEffect(() => {
console.log(singleValue); // logs the selected option or null
}, [singleValue]);
return (
<FormField>
<Label>Select a country</Label>
<SelectV2
clearable
name="country-selectV2"
value={singleValue}
onChange={setSingleValue}
>
<SelectV2.Content>
<SelectV2.Option value="austria">Austria</SelectV2.Option>
<SelectV2.Option value="germany">Germany</SelectV2.Option>
<SelectV2.Option value="italy">Italy</SelectV2.Option>
<SelectV2.Option value="spain">Spain</SelectV2.Option>
</SelectV2.Content>
</SelectV2>
</FormField>
);
};
Hope this helps.
28 Jun 2024 04:08 PM
I am using - 0.111.7 - so I will check with the latter version and let you know! Thank you!
02 Jul 2024 07:31 AM
Hi @veranika_k - I hope the solution above solution worked for you, if so, please 'accept as solution', to help us close this community question.
Thanks, Penny