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

Use more generic HTMLElement type for DOM elements #3169

Merged
merged 1 commit into from May 3, 2024

Conversation

RobinMalfait
Copy link
Collaborator

We keep specific types for elements with special meaning, such as HTMLButtonElement, HTMLLabelElement or HTMLInputElement because they receive certain attributes that generic DOM nodes (such as HTMLDivElement) don't

For the components where we use simple div elements by default (and where people use as={...} that renders a different element), it doesn't make sense to use HTMLDivElement. Using a more generic HTMLElement is simpler and more correct.

E.g.: we still had HTMLUListElement and HTMLLIElement for "div" DOM nodes which is incorrect.

This shouldn't be a breaking change because an HTMLDivElement is still a valid HTMLElement. The other way around wouldn't be the case.

We keep specific types for elements with special meaning, such as
`HTMLButtonElement`, `HTMLLabelElement` or `HTMLInputElement` because
they receive certain attributes that generic DOM nodes (such as
HTMLDivElement) don't

For the components where we use simple `div` elements (and where people
use `as={...}`) that renders a different element, it doesn't make sense
to use `HTMLDivElement`. Using a more generic `HTMLElement` is simpler
and more correct (we still had `HTMLUListElement` and `HTMLLIElement`
for "div" DOM nodes which is incorrect).

This shouldn't be a breaking change because an `HTMLDivElement` is still
a valid `HTMLElement`. The other way around wouldn't be the case.
Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 0:43am
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 0:43am

@RobinMalfait RobinMalfait changed the title Use more generic HTMLElement type Use more generic HTMLElement type for DOM elements May 3, 2024
@RobinMalfait RobinMalfait merged commit 0bd8c47 into main May 3, 2024
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/improve-element-types branch May 3, 2024 13:32
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.

None yet

2 participants