Skip to content

Multple classes aren't allowed in chosenClass #2443

Description

@Tyler-Petrov

So I'm curious if forcing only one class in the chosenClass property (ie no whitespace) is intended or advantageous for everyone. For those of us who are using tailwind, it would be really nice to have multiple classes be an option.

Here's a codepen just for giggles.

Activity

  1. mrleblanc101 commented on Sep 19, 2025

    @mrleblanc101

    Same for ghost-class

  2. jankapunkt commented on May 5, 2026

    @jankapunkt

    I can just assume that it was created during a time when manual plain css was the goto way. In days of tailwind etc. this is obviously not desired.

  3. jankapunkt commented on May 5, 2026

    @jankapunkt

    Here is a minimal example that is backward compatible and es5 compatible.

    @owen-m1 if you don't see any issues with it I can create a PR what do you think?

    function toggleClass(el, name, state) {
        if (el && name) {
          var _toggle = function (_name, _state) {
            if (el.classList) {
              el.classList[_state ? 'add' : 'remove'](_name);
            } else {
              var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + _name + ' ', ' ');
              el.className = (className + (_state ? ' ' + _name : '')).replace(R_SPACE, ' ');
            } 
          }
          var names = name.split(' ');
          for (var i = 0; i < names.length; i++) {
            _toggle(names[i], state);
          }
        }
    }

    Usage example:

    <div id="moo" class="lol">text</div>
    <button onclick="toggleClasses()">toggle</button>
    .foo {
      font-weight: bold;
    }
    
    .bar {
      color: #f00;
    }
    let state = false
    function toggleClasses () {
      const el = document.querySelector('#moo')
      toggleClass(el, 'foo bar', !state)
      state = !state
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions