Skip to content

className with object containing toString() method isn't working as expected #2599

Description

@resetko

Steps

  1. Put object with toString() method to className prop for Button or any other component
  2. Check out generated class name

Code example:

import React from "react";
import { render } from "react-dom";
import { Button } from "semantic-ui-react";

class BEM {
  constructor(blockName) {
    this.block = blockName;
  }

  el(element) {
    return {
      mod: modf => `${this.block}__${element}--${modf}`,
      toString: () => `${this.block}__${element}`
    };
  }

  toString() {
    return `${this.block}`;
  }
}

const App = () => {
  const css = new BEM("block");
  return (
    <div className={css}>
      <button className={css.el("native")}>Native button</button>
      <br />
      <Button className={css.el("semantic")}>Semantic button</Button>
    </div>
  );
};

render(<App />, document.getElementById("app"));

Expected Result

<div id="app">
    <div class="block">
        <button class="block__native">Native button</button>
        <br>
        <button class="ui button mod block_semantic" role="button">Semantic button</button>
    </div>
</div>

Actual Result

<div id="app">
    <div class="block">
        <button class="block__native">Native button</button>
        <br>
        <button class="ui button mod toString" role="button">Semantic button</button>
    </div>
</div>

With warning for propType violation

Version

0.78.3

Testcase

https://codesandbox.io/s/j25zwlxmmw

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions