You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import * as React from "react";
import { ToggleGroup } from "radix-ui";
import { type Alignment, Alignments } "./somewhere";
export default () => {
const [value, setValue] = React.useState(Alignments.Left);
// could be something like
// const [value, setValue] = React.useState<Alignment>(Alignments.Left);
return (
// perhaps something like this
// <ToggleGroup.Root<Alignment>
<ToggleGroup.Root
type="single"
value={value}
onValueChange={(value) => { // this would be assumed to be a union of all the available value-s on the `Item`s
if (value) setValue(value);
}}
>
<ToggleGroup.Item value={Alignments.Left}> // here using value="" would autocomplete string-ed values
<TextAlignLeftIcon />
</ToggleGroup.Item>
<ToggleGroup.Item value={Alignments.Center}>
<TextAlignCenterIcon />
</ToggleGroup.Item>
<ToggleGroup.Item value={Alignments.Right}>
<TextAlignRightIcon />
</ToggleGroup.Item>
</ToggleGroup.Root>
);
};
being able to autocomplete the value and knowing specific values the Root component shall have based on the Items it has and/or limiting the Items possible values they can have
this looks like an overkill on this example, but for more complex functionalities it would avoid us to need something like
onValueChange={(value) => {
if (value) setValue(value as SomeType);
}}
or even worse
onValueChange={(value) => {
if (value) setValue(value as unknown as SomeType);
}}
opening discussion before trying out a PR for this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
currently, with this example as a basis
I'd like to have something like this
being able to autocomplete the value and knowing specific
value
s theRoot
component shall have based on theItem
s it has and/or limiting theItem
s possiblevalue
s they can havethis looks like an overkill on this example, but for more complex functionalities it would avoid us to need something like
or even worse
opening discussion before trying out a PR for this
Beta Was this translation helpful? Give feedback.
All reactions