For certain components - for example input, heading, or inset text - it could be useful to be able to add attributes without needing to update the component.
There are supported attributes already - for example, in the input component the following:
To avoid unwanted behaviour, a block-list or an allow-list should be used to block unwanted attributes or only allow wanted attributes. Using a list would allow an error to be thrown for known problematic attributes with a link to the documentation explaining why they're not allowed.
Other thoughts
What happens when an attribute is passed in twice - once outside the attributes hash and once inside?
Should attributes be allowed or blocked?
What attributes should be inside the options hash, and what should be outside? In the example above, id is outside and spellcheck is inside.
For certain components - for example input, heading, or inset text - it could be useful to be able to add attributes without needing to update the component.
There are supported attributes already - for example, in the input component the following:
will generate the following HTML:
But (at the time of writing) the
spellcheck
attribute to the input component isn't currently supported.To get
spellcheck
supported would mean:and step 3 would need to be repeated for each frontend application.
This is quite laborious.
Instead, an
attributes
parameter could be used to pass in attributes - similar to how the Rail'scontent_tag
accepts a hash in its options.This would mean that any new non-default attribute could be used easily:
should generate
This is similar to how some components have a
data_attributes
parameter for addingdata-
attributes - for example, the button component, details component, and the accordion component.To avoid unwanted behaviour, a block-list or an allow-list should be used to block unwanted attributes or only allow wanted attributes. Using a list would allow an error to be thrown for known problematic attributes with a link to the documentation explaining why they're not allowed.
Other thoughts
id
is outside andspellcheck
is inside.