Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Filter invalid span props #584

wants to merge 4 commits into from

Conversation

jhp0621
Copy link
Contributor

@jhp0621 jhp0621 commented Feb 2, 2023

Release Notes

Author Checklist

  • Add unit test(s)
  • Update version in package.json (see the versioning guidelines)
  • Update documentation (if necessary)
  • Add story to storybook (if necessary)
  • Assign dev reviewer

@jhp0621
Copy link
Contributor Author

jhp0621 commented Feb 3, 2023

@chawes13 Can I get general feedback on the approach/util before I proceed with adding unit tests and updating other instances of filterInvalidDOMProps?

@@ -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
Copy link
Contributor

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-")
Copy link
Contributor

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
Copy link
Contributor

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-"
Copy link
Contributor

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?

Comment on lines +39 to +41
return omitBy(validDOMProps, (_, key) =>
notAllowedAttributes.includes(htmlAttributes[key])
)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants