Skip to content

Questions around how the Select machine works and why #598

Answered by segunadebayo
lvl-mattwells asked this question in Q&A
Discussion options

You must be logged in to vote

Why does Zag.js add ids to every element part?

We do this for two reasons:

  • Accessibility: As you might know, we need to assign ids to the correct elements to get the aria-* and htlmFor attributes working correctly.

  • Finding DOM Elements: Due to the fact that Zag.js is framework agnostic, the idea of ref can't be used here; we rely on the good ole document.getElementById to locate elements in the DOM. We also ensure it works in custom window environments and ShadowDOM.

Okay. I get that, but how do I override the ids?

Every machine has a ids property you can pass to the context to modify the id of any part to match what you want.

You can use this to compose the FormControl and FormLabe…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by lvl-mattwells
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants