Skip to content
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

Checkbox component does not work with variables (MT v3) #839

Open
Popa-42 opened this issue Nov 12, 2024 · 0 comments
Open

Checkbox component does not work with variables (MT v3) #839

Popa-42 opened this issue Nov 12, 2024 · 0 comments

Comments

@Popa-42
Copy link

Popa-42 commented Nov 12, 2024

Short Summary

The MT component does not (visually) change its value dynamically with an associated variable.

Steps to Reproduce

This is a short example showing just a <Checkbox> element that should change its checked state every second.

"use client";
import { Checkbox } from "@material-tailwind/react";
import { useState, useEffect } from "react";

export default function CheckboxExample() {
  const [checked, setChecked] = useState(false);

  useEffect(() => {
    const interval = setInterval(() => {
      setChecked((prev) => !prev); // Toggle checked state every second
    }, 1000);

    return () => clearInterval(interval);
  }, []);

  // Render the checkbox with the value of 'checked'
  return (
    <div>
      <Checkbox checked={checked}>
        <Checkbox.Indicator/>
      </Checkbox>
    </div>
  );
}

Expected Behaviour

The checkbox should visually toggle between checked and unchecked states every second.

Actual Behaviour

The visual state of the checkbox does not update dynamically. However, inspecting the underlying (invisible) <input> element shows that its checked attribute does at least toggle this element's state as expected.

It seems the visual state of the <label> element is controlled by the data-checked attribute, which does not update dynamically.

Material Tailwind Version

I used @material-tailwind/react version 3.0.0-beta.24

@Popa-42 Popa-42 changed the title Checkbox component does not work with variables Checkbox component does not work with variables (MT v3) Nov 12, 2024
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

No branches or pull requests

1 participant