Skip to content

🐛 fix: Dynamically setting className on Baloise React components removes default styles (@baloise/ds-react) #1846

@glennverschooren

Description

@glennverschooren

Current Behavior

When dynamically setting the className prop on a Baloise React component (e.g., BalCard), the component loses its default styles and only applies the custom classes. This happens when the class is updated after an event (e.g., button click). The expected behavior is that custom classes should be merged with the component’s default classes, not replace them.

import "@baloise/ds-styles/css/all.css";
import "./styles.css";
import { BalCard, BalButton } from "@baloise/ds-react";
import { useState } from "react";

export default function App() {
  const [customClassNames, setCustomClassNames] = useState<string>("bg-green");

  const updateCustomClassNames = () => {
    setCustomClassNames("bg-red p-large");
  };

  return (
    <div className="App">
      <div className="container pt-large">
        <BalCard className={customClassNames}>hellooo</BalCard>
        <BalButton
          onClick={updateCustomClassNames}
          className={customClassNames}
        >
          Text button
        </BalButton>
      </div>
    </div>
  );
}

Expected Behavior

Custom classes should be merged with the component’s default classes. For example, after updating the class, should still have its rounded border and default layout, in addition to the new background color and padding.

Steps to Reproduce

  1. Render a Baloise component (e.g., ) with a custom className.
  2. Update the className dynamically (e.g., after clicking a button).
  3. Observe that the component loses its default styles (e.g., rounded borders, layout).

Version

19.8.2

Browsers

Chrome

Device

Desktop

Code Reproduction URL

https://codesandbox.io/p/sandbox/c53gsl

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

🐛 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions