Skip to content

Update Label to Leptos 0.7 #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 84 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
[workspace]
# Temporarily disabled to upgrade individual packages to Leptos 0.7.
# members = [
# "book-examples/*/*",
# "packages/colors",
# "packages/icons/*",
# "packages/primitives/*/*",
# "packages/themes/*",
# "scripts",
# "stories/*",
# ]
# Temporarily disabled subcrates to be upgraded individually to Leptos 0.7.
# Once a crate is ready, uncomment it here.
members = [
"book-examples/*/*",
"packages/colors",
"packages/icons/*",
"packages/primitives/leptos/accessible-icon",
"packages/primitives/leptos/arrow",
"packages/primitives/leptos/aspect-ratio",
"packages/primitives/leptos/direction",
"packages/primitives/leptos/id",
"packages/icons/dioxus",
"packages/icons/yew",

# -- Leptos Primitives (commented until they're upgraded) --
# "packages/primitives/leptos/accessible-icon",
# "packages/primitives/leptos/arrow",
# "packages/primitives/leptos/aspect-ratio",
# "packages/primitives/leptos/avatar",
# "packages/primitives/leptos/checkbox",
# "packages/primitives/leptos/collection",
# "packages/primitives/leptos/compose-refs",
# "packages/primitives/leptos/direction",
# "packages/primitives/leptos/dismissable-layer",
# "packages/primitives/leptos/dropdown-menu",
# "packages/primitives/leptos/focus-guards",
# "packages/primitives/leptos/focus-scope",
# "packages/primitives/leptos/id",
"packages/primitives/leptos/label",
"packages/primitives/leptos/use-controllable-state",
"packages/primitives/leptos/use-escape-keydown",
"packages/primitives/leptos/use-previous",
"packages/primitives/leptos/use-size",
"packages/primitives/leptos/visually-hidden",
# "packages/primitives/leptos/menu",
# "packages/primitives/leptos/popover",
# "packages/primitives/leptos/popper",
# "packages/primitives/leptos/portal",
# "packages/primitives/leptos/presence",
"packages/primitives/leptos/primitive",
# "packages/primitives/leptos/progress",
# "packages/primitives/leptos/roving-focus",
# "packages/primitives/leptos/select",
# "packages/primitives/leptos/separator",
# "packages/primitives/leptos/slot",
# "packages/primitives/leptos/switch",
# "packages/primitives/leptos/tabs",
# "packages/primitives/leptos/toggle",
# "packages/primitives/leptos/use-controllable-state",
# "packages/primitives/leptos/use-escape-keydown",
# "packages/primitives/leptos/use-previous",
# "packages/primitives/leptos/use-size",
# "packages/primitives/leptos/visually-hidden",

# -- Yew Primitives --
"packages/primitives/yew/*",

# -- Themes, Scripts, and Stories --
"packages/themes/yew",
"scripts",
"stories/*",
]

resolver = "2"

[workspace.package]
Expand All @@ -39,14 +61,17 @@ repository = "https://github.com/RustForWeb/radix"
version = "0.0.2"

[workspace.dependencies]
console_log = "1.0.0"
console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
dioxus = "0.6.1"
leptos = "0.7.2"
leptos_dom = "0.7.2"
leptos_router = "0.7.2"
leptos-node-ref = "0.0.3"
leptos-maybe-callback = "0.0.3"
leptos-style = "0.0.3"
leptos-typed-fallback-show = "0.0.3"
leptos-use = "0.15.2"
log = "0.4.22"
send_wrapper = "0.6.0"
serde = "1.0.198"
Expand All @@ -58,6 +83,43 @@ yew-router = "0.18.0"
yew-struct-component = "0.1.4"
yew-style = "0.1.4"

# Subcrate packages (paths remain the same; you can comment out any subcrate not yet upgraded).
# We centralize shared dependencies in [workspace.dependencies] for a single source of truth,
# reducing duplication, preventing version drift, and keeping the Cargo.lock consistent.
#radix-leptos-arrow.path = "./packages/primitives/leptos/arrow"
#radix-leptos-aspect-ratio.path = "./packages/primitives/leptos/aspect-ratio"
#radix-leptos-accessible-icon.path = "./packages/primitives/leptos/accessible-icon"
#radix-leptos-avatar.path = "./packages/primitives/leptos/avatar"
#radix-leptos-checkbox.path = "./packages/primitives/leptos/checkbox"
#radix-leptos-collection.path = "./packages/primitives/leptos/collection"
#radix-leptos-compose-refs.path = "./packages/primitives/leptos/compose-refs"
#radix-leptos-direction.path = "./packages/primitives/leptos/direction"
#radix-leptos-dismissable-layer.path = "./packages/primitives/leptos/dismissable-layer"
#radix-leptos-dropdown-menu.path = "./packages/primitives/leptos/dropdown-menu"
#radix-leptos-focus-guards.path = "./packages/primitives/leptos/focus-guards"
#radix-leptos-focus-scope.path = "./packages/primitives/leptos/focus-scope"
#radix-leptos-id.path = "./packages/primitives/leptos/id"
radix-leptos-label.path = "./packages/primitives/leptos/label"
#radix-leptos-menu.path = "./packages/primitives/leptos/menu"
#radix-leptos-popper.path = "./packages/primitives/leptos/popper"
#radix-leptos-portal.path = "./packages/primitives/leptos/portal"
#radix-leptos-presence.path = "./packages/primitives/leptos/presence"
radix-leptos-primitive.path = "./packages/primitives/leptos/primitive"
#radix-leptos-progress.path = "./packages/primitives/leptos/progress"
#radix-leptos-roving-focus.path = "./packages/primitives/leptos/roving-focus"
#radix-leptos-select.path = "./packages/primitives/leptos/select"
#radix-leptos-separator.path = "./packages/primitives/leptos/separator"
#radix-leptos-slot.path = "./packages/primitives/leptos/slot"
#radix-leptos-switch.path = "./packages/primitives/leptos/switch"
#radix-leptos-tabs.path = "./packages/primitives/leptos/tabs"
#radix-leptos-toggle.path = "./packages/primitives/leptos/toggle"
#radix-leptos-use-controllable-state.path = "./packages/primitives/leptos/use-controllable-state"
#radix-leptos-use-escape-keydown.path = "./packages/primitives/leptos/use-escape-keydown"
#radix-leptos-use-previous.path = "./packages/primitives/leptos/use-previous"
#radix-leptos-use-size.path = "./packages/primitives/leptos/use-size"
#radix-leptos-visually-hidden.path = "./packages/primitives/leptos/visually-hidden"

[patch.crates-io]
yew = { git = "https://github.com/RustForWeb/yew.git", branch = "feature/use-composed-ref" }
yew-router = { git = "https://github.com/RustForWeb/yew.git", branch = "feature/use-composed-ref" }
leptos-node-ref = { git = "https://github.com/geoffreygarrett/leptos-utils", branch = "feature/any-node-ref" }
91 changes: 48 additions & 43 deletions book/src/primitives/components/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,12 @@

Renders an accessible label associated with controls.

{{#tabs global="framework" }}
{{#tab name="Leptos" }}

```toml,trunk
package = "radix-leptos-book-primitives"
features = ["label"]
files = ["src/label.rs"]
```

{{#endtab }}
{{#tab name="Yew" }}

```toml,trunk
package = "radix-yew-book-primitives"
features = ["label"]
files = ["src/label.rs"]
```

{{#endtab }}
{{#endtabs }}

## Features

- Text selection is prevented when double clicking label.
- Supports nested controls.
- Text selection is prevented when double-clicking label
- Supports nested controls
- Composable with other elements using `as_child`
- Handles mouse events with proper focus management

## Installation

Expand All @@ -39,9 +20,9 @@ Install the component from your command line.
cargo add radix-leptos-label
```

- [View on crates.io](https://crates.io/crates/radix-leptos-label)
- [View on docs.rs](https://docs.rs/radix-leptos-label/latest/radix_leptos_label/)
- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/leptos/label)
- [View on crates.io](https://crates.io/crates/radix-leptos-label)
- [View on docs.rs](https://docs.rs/radix-leptos-label/latest/radix_leptos_label/)
- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/leptos/label)

{{#endtab }}
{{#tab name="Yew" }}
Expand All @@ -50,9 +31,9 @@ cargo add radix-leptos-label
cargo add radix-yew-label
```

- [View on crates.io](https://crates.io/crates/radix-yew-label)
- [View on docs.rs](https://docs.rs/radix-yew-label/latest/radix_yew_label/)
- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/yew/label)
- [View on crates.io](https://crates.io/crates/radix-yew-label)
- [View on docs.rs](https://docs.rs/radix-yew-label/latest/radix_yew_label/)
- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/yew/label)

{{#endtab }}
{{#endtabs }}
Expand All @@ -71,7 +52,9 @@ use radix_leptos_label::*;
#[component]
fn Anatomy() -> impl IntoView {
view! {
<Label />
<Label>
"Label text"
</Label>
}
}
```
Expand All @@ -83,10 +66,12 @@ fn Anatomy() -> impl IntoView {
use radix_yew_label::*;
use yew::prelude::*;

#[component]
fn Anatomy() -> impl IntoView {
view! {
<Label />
#[function_component]
fn Anatomy() -> Html {
html! {
<Label>
{"Label text"}
</Label>
}
}
```
Expand All @@ -103,25 +88,45 @@ Contains the content for the label.
{{#tabs global="framework" }}
{{#tab name="Leptos" }}

| Prop | Type | Default |
| --------------- | ------------------------------ | ------- |
| `on_mouse_down` | `Option<Callback<MouseEvent>>` | - |
| Prop | Type | Default | Description |
|-----------------|--------------------------------------------|---------|-------------------------------------------------------------------|
| `children` | `TypedChildrenFn<impl IntoView + 'static>` | - | The content to be rendered inside the label |
| `as_child` | `MaybeProp<bool>` | `false` | Change the default rendered element for the one passed as a child |
| `on_mouse_down` | `MaybeCallback<MouseEvent>` | - | Event handler for mousedown events |
| `node_ref` | `AnyNodeRef` | - | A reference to the underlying DOM node |

{{#endtab }}
{{#tab name="Yew" }}

| Prop | Type | Default |
| --------------- | ----------------------------------------- | ------- |
| `as_child` | `Option<Callback<LabelChildProps, Html>>` | - |
| `on_mouse_down` | `Option<Callback<MouseEvent>>` | - |
| Prop | Type | Default | Description |
|-----------------|-------------------------------------------|---------|-------------------------------------|
| `as_child` | `Option<Callback<LabelChildProps, Html>>` | - | Change the default rendered element |
| `on_mouse_down` | `Option<Callback<MouseEvent>>` | - | Event handler for mousedown events |

{{#endtab }}
{{#endtabs }}

## Behavior

The Label component includes the following built-in behaviors:

- Prevents text selection when double-clicking
- Ignores mousedown events on nested controls (button, input, select, textarea)
- Supports composition via `as_child` prop
- Can be associated with controls both by wrapping them or using the `for` attribute

## Accessibility

This component is based on the native `label` element, it will automatically apply the correct labelling when wrapping controls or using the `for` attribute. For your own custom controls to work correctly, ensure they use native elements such as `button` or `input` as a base.
This component is based on the native `label` element, it will automatically apply the correct labelling when wrapping
controls or using the `for` attribute. For your own custom controls to work correctly, ensure they use native elements
such as `button` or `input` as a base.

When using custom components within labels:

- Ensure they ultimately render to native form elements
- Verify that click events properly propagate through to the underlying control
- Test with screen readers to confirm proper label association

## See Also

- [Radix documentation](https://www.radix-ui.com/primitives/docs/components/label)
- [Radix documentation](https://www.radix-ui.com/primitives/docs/components/label)
3 changes: 3 additions & 0 deletions packages/primitives/leptos/label/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ version.workspace = true

[dependencies]
leptos.workspace = true
leptos-node-ref.workspace = true
leptos-maybe-callback.workspace = true
radix-leptos-primitive.workspace = true
web-sys.workspace = true
Loading