dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Modifying Body attributes like we can do Head

Open rogusdev opened this issue 1 year ago • 3 comments

Feature Request

Per: https://discord.com/channels/899851952891002890/1309445758705074197/1309878444355747992

rogusdev avatar Nov 25 '24 03:11 rogusdev

While we are on this topic, it is better to take of the html tag as well. Use case from tailwind

  <html class="h-full bg-gray-100">
  <body class="h-full">

chungwong avatar Nov 25 '24 05:11 chungwong

A somewhat related problem is that the starter project created by dx new has a main.css with styling for the body background, but none of the CSS automatically applies. This requires making some modifications before any of the CSS does anything.

ChooKing avatar Nov 25 '24 17:11 ChooKing

@ChooKing is that actually related? This is a feature request for a Dioxus element to programmatically modify the Body and Html tags. Css is a separate problem, and it seems to me that changes to the dx new starter project are definitely separate.

rogusdev avatar Dec 01 '24 20:12 rogusdev

A workaround I found is to use eval().

#[component]
pub fn NavBar() -> Element {
    document::eval(r#"document.body.classList.add('dark')"#);
    let rotate_color_scheme = move |_| {
        document::eval(
            r#"
                document.body.classList.toggle('dark');
                document.body.classList.toggle('light');
            "#,
        );
    };

    rsx! {
          div { id: "navbar",
              Link { to: Route::Home {}, "Home" }
              Link { to: Route::Blog { id: 1 }, "Blog" }
              button { onclick: rotate_color_scheme, "Color" }
          }
      }
}

nilswloewen avatar Oct 22 '25 06:10 nilswloewen