Replies: 1 comment 1 reply
-
|
This is a limitation of the Rust typing system that you cannot have Union types as you would in TypeScript. In Rust, if you want a user to choose only 1 variant, you need to use an enum. #[derive(PartialEq, Clone)]
enum TitleKind {
#[default]
Title,
AriaLabel,
}
#[derive(Properties, PartialEq, Clone)]
pub struct CompProps {
title: AttrValue,
#[prop_or_default]
title_kind: TitleKind,
}
// Defaults to title.
html! { <Comp title={title} /> };
// Sets the title kind to aria label.
html! { <Comp title={title} title_kind={TitleKind::AriaLabel} /> }; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My component has a requirement that the
aria-labelattribute should be set if thetitleattribute is not set.I don't see a way with the
#[prop_or_......]macros.Beta Was this translation helpful? Give feedback.
All reactions