cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SelectV2

veranika_k
Helper

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 

3 REPLIES 3

educampver
Dynatrace Advisor
Dynatrace Advisor

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.

I am using - 0.111.7 - so I will check with the latter version and let you know! Thank you!

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 

Featured Posts