Skip to content

Type of class attribute allows array of strings #3

Description

@rothsandro

Describe the bug
The parameter type of the class attribute function accepts a string or an array of strings.
But when using an array it will call .join() which results in class="one,two,three".

class-ts

To Reproduce
Steps to reproduce the behavior:

  1. Create an element: h.p.class(['one', 'two', 'three'])('hello')
  2. Inspect the element in the DOM
  3. The classes are joined with ,
<p class="one,two,three">hello</p>

Expected behavior
The classes should be joined using spaces:

<p class="one two three">hello</p>

Screenshots
class-join

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Brave
  • Version: 1.36
  • Node: 16.13.0
  • Eleventy: 1.0.0

Additional context
Right now we either need to use a string or add a custom plugin:

setPlugins(h, [
  {
    attribute: (tagName, key, args) => {
      if (key === "class" && Array.isArray(args)) {
        return [key, args.join(" ")];
      }
      return [key, args];
    },
  },
]);

Metadata

Metadata

Assignees

Labels

Projects

Status
In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions