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
-
My component has a requirement that the
aria-label
attribute should be set if thetitle
attribute is not set.I don't see a way with the
#[prop_or_......]
macros.Beta Was this translation helpful? Give feedback.
All reactions