-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter invalid span props #584
base: main
Are you sure you want to change the base?
Conversation
@chawes13 Can I get general feedback on the approach/util before I proceed with adding unit tests and updating other instances of |
@@ -0,0 +1,54 @@ | |||
import { htmlElementAttributes } from 'html-element-attributes' | |||
import htmlAttributes from 'html-attributes' // An object of all HTML attributes with the JSX prop (e.g., "className", "tabIndex") as keys and the JavaScript prop (e.g., "class", "tabindex") as values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the value the "JavaScript prop" or the html attribute?
import { difference, omitBy, compact, concat } from 'lodash' | ||
import filterInvalidDOMProps from 'filter-invalid-dom-props' | ||
|
||
// An array of basic HTML _global_ attributes (note: this does not include event handlers, "aria-", "role", and "data-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe provide a link to the global attributes mdn documentation?
* A function that filters out props 1) that are not recognized as a valid HTML attribute | ||
* and 2) that are valid HTML attributes but not allowed for the provided element. | ||
* | ||
* @param {String} element - HTML element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little confused when I read this because HTML element and String seem contradictory. Can we be more explicit by saying something like, "HTML element name"?
*/ | ||
|
||
function filterInvalidHtmlProps(element, props) { | ||
// This util (filterInvalidDOMProps) covers event handlers such as "onClick" and props that begin with "data-" and "aria-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "covers" mean in this context?
return omitBy(validDOMProps, (_, key) => | ||
notAllowedAttributes.includes(htmlAttributes[key]) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be optimized, but I think we should only look at that after benchmarking filterInvalidHtmlProps
against filterinvalidDOMProps
.
It probably does make sense to write specs first, since then you can change the underlying code under green with confidence.
Release Notes
Author Checklist