GithubHelp home page GithubHelp logo

html-attributes-utils's People

Contributors

peteryates avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sobakasu

html-attributes-utils's Issues

Enhancement: Support for Turbo and Stimulus attributes

We'd like to use this library for managing attributes in ViewComponent models that use Turbo and Stimulus. We'd be happy to contribute PRs if this is in line with your project goals, but want to get your input first.

We have three blockers currently:

  1. Support for stimulus controller and action attributes that require merges:

Input:

def default_attributes
  { data: { controller: "default", action: "click->extra#event" }}
end
...
Component.new(data: { controller: "extra", action: "click->extra#event" })

Desired output:

<div data-controller="default extra" data-action="click->default#event click->extra#event">
  1. Automatic flattening of merged arrays

... Rails accepts them as arrays so there's no need to convert back to strings.

Adding custom configuration for the above attributes reveals that the documentation is not correct in general.

  1. deep_tidy_html_attributes removes empty strings

This is in line with the documented behaviour, but it's surprising given that the usual behaviour of Rails tag rendering is that an attribute with an empty string becomes a bare attribute, e.g.

Input:

tag.div(hidden: "", data: { turbo_stream: "" })

Output:

<div hidden data-turbo-stream>

Rails will remove attributes with nil values, but empty string attributes are usually rendered.

Could you perhaps explain the reasoning for removing empty attributes via deep_tidy_html_attributes? It's not clear from the documentation why this feature is helpful.

If you'd be happy to accept PRs for any or all of these suggested enhancements please let us know.

Consider conversion of `data-`/`aria-` prefixed keys to nested variants

In Rails there are two ways of setting data and aria attributes when using the tag and content_tag helpers. These are to set the attribute by its full name data-controller: "abc", data-response: "xyz" or to use a nested hash: data: { controller: "abc", response: "xyz" }.This library, and both the components and form builder assume people are using the latter. Using the former might lead to unintended consequences.

It might make sense to detect the full name variant and either apply a conversion or provide some kind of warning to the developer. As this only applies to data- and aria- prefixed attributes the conversion should be straightforward.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.