Skip to content

Conversation

@AnttiJalomaki
Copy link
Contributor

@AnttiJalomaki AnttiJalomaki commented Jan 23, 2026

Summary

  • Fix toolbar demo where bold/italic/underline buttons only toggled ON but never OFF
  • Add visual pressed state indication to toolbar buttons

Root Cause

The original demo had two issues:

  1. Broken toggle logic: The toggle_style function called retain() to remove the style, then unconditionally push() to re-add it - making toggle OFF impossible
  2. Reactive subscription issue: Passing a use_memo value directly to the style attribute didn't properly subscribe in the reactive context, so style changes weren't reflected in the DOM

Solution

  • Replaced Vec-based state with individual Signal<bool> for each style, using .toggle()
  • Used Dioxus's native CSS-in-RSX individual properties (font_weight, font_style, text_decoration, text_align) instead of a computed style string
  • Reading signals directly in RSX conditionals ensures proper reactive subscriptions
  • Added data-state attribute and CSS for visual button pressed state

Test plan

  • Same for Italic and Underline
  • Click Bold again → text returns to normal, button shows unpressed state
  • Multiple styles can be combined and individually toggled
  • Click Bold → text becomes bold, button shows pressed state
  • Alignment buttons work and show active state

- Replace broken Vec-based toggle logic with individual boolean signals
- Use Dioxus native CSS-in-RSX properties instead of style string memo
- Add data-state attribute for visual button pressed state
- Add CSS styling for pressed toolbar buttons
@github-actions
Copy link

@AnttiJalomaki AnttiJalomaki marked this pull request as draft January 23, 2026 17:23
@AnttiJalomaki AnttiJalomaki marked this pull request as ready for review January 23, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant