Skip to content

Conversation

@nelstrom
Copy link
Contributor

@nelstrom nelstrom commented Oct 4, 2025

Summary

This PR addresses issue #1149 by allowing ADD_ATTR to accept a function for tag-specific attribute validation.

Background & Context

Currently, ADD_ATTR only accepts a string array, creating a flat list of allowed attributes that applies to all tags. This limitation means you cannot specify that certain attributes should only be allowed on specific tags without writing custom hooks.

Tasks

First Commit: Extends ADD_ATTR to accept either a string array (for backwards compatibility) or a function with signature (attributeName: string, tagName: string) => boolean. When a function is provided, it enables granular control over which attributes are allowed for specific tags.

Second Commit: Extends the same pattern to ADD_TAGS, allowing it to accept a function with signature (tagName: string) => boolean for consistency. If you prefer to keep the scope limited to the original issue, I'm happy to drop this commit or squash both together.

Dependencies

n/a

Allow ADD_ATTR configuration option to receive a function with signature
(attributeName: string, tagName: string) => boolean, enabling granular
control over which attributes are allowed for specific elements.
Allow ADD_TAGS configuration option to receive a function with signature
(tagName: string) => boolean, enabling granular control over which tags
are allowed.
@cure53 cure53 merged commit fa239f0 into cure53:main Oct 5, 2025
8 checks passed
@cure53
Copy link
Owner

cure53 commented Oct 5, 2025

Amazing, thank you very much! ❤️

@nelstrom nelstrom deleted the add-attr-as-function branch October 6, 2025 09:40
@nelstrom
Copy link
Contributor Author

nelstrom commented Oct 6, 2025

Thanks for accepting this. I already have a case where I'd like to use this feature. Will you be cutting another release anytime soon?

@cure53
Copy link
Owner

cure53 commented Oct 6, 2025

I say thanks 🙂 And yes, maybe this week, latest next week.

cure53 added a commit that referenced this pull request Oct 13, 2025
* Update README.md

* Update README.md

* Update README.md

* fix: Removed slot as SVG element, leaving it for HTML, see #1174

* feat: allow ADD_ATTR to accept a function

Allow ADD_ATTR configuration option to receive a function with signature
(attributeName: string, tagName: string) => boolean, enabling granular
control over which attributes are allowed for specific elements.

* feat: allow ADD_TAGS to accept a function

Allow ADD_TAGS configuration option to receive a function with signature
(tagName: string) => boolean, enabling granular control over which tags
are allowed.

* Allow ADD_ATTR and ADD_TAGS to accept a function (#1150)

* feat: allow ADD_ATTR to accept a function

Allow ADD_ATTR configuration option to receive a function with signature
(attributeName: string, tagName: string) => boolean, enabling granular
control over which attributes are allowed for specific elements.

* feat: allow ADD_TAGS to accept a function

Allow ADD_TAGS configuration option to receive a function with signature
(tagName: string) => boolean, enabling granular control over which tags
are allowed.

* Update README.md (#1151)

* feat: add "mask-type" SVG attribute (resolves #1154) (#1155)

* chore: Preparing 3.3.0 release

---------

Co-authored-by: Drew Neil <[email protected]>
Co-authored-by: Prasad Rajandran <[email protected]>
cure53 added a commit that referenced this pull request Oct 13, 2025
* Update README.md

* Update README.md

* Update README.md

* fix: Removed slot as SVG element, leaving it for HTML, see #1174

* feat: allow ADD_ATTR to accept a function

Allow ADD_ATTR configuration option to receive a function with signature
(attributeName: string, tagName: string) => boolean, enabling granular
control over which attributes are allowed for specific elements.

* feat: allow ADD_TAGS to accept a function

Allow ADD_TAGS configuration option to receive a function with signature
(tagName: string) => boolean, enabling granular control over which tags
are allowed.

* Allow ADD_ATTR and ADD_TAGS to accept a function (#1150)

* feat: allow ADD_ATTR to accept a function

Allow ADD_ATTR configuration option to receive a function with signature
(attributeName: string, tagName: string) => boolean, enabling granular
control over which attributes are allowed for specific elements.

* feat: allow ADD_TAGS to accept a function

Allow ADD_TAGS configuration option to receive a function with signature
(tagName: string) => boolean, enabling granular control over which tags
are allowed.

* Update README.md (#1151)

* feat: add "mask-type" SVG attribute (resolves #1154) (#1155)

* chore: Preparing 3.3.0 release

---------

Co-authored-by: Drew Neil <[email protected]>
Co-authored-by: Prasad Rajandran <[email protected]>
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