Skip to content
\n

While there is an ids prop at the root, this pitfall isn't explicitly mentioned anywhere in the documentation. I think it's natural to assume that some users might want to supply their own id for the label.

\n

To solve this, the id retrieval could do a check for an existing ID, i.e.:

\n
export const getLabelId = (ctx: Scope) => {\n  const labelId = getLabelId(ctx)\n  if (ctx.getById(labelId)) {\n    return labelId\n  }\n  const labelEl = getRootEl(ctx)?.querySelector(`[data-part=\"label\"]`)\n  return labelEl?.id || undefined\n}
\n

Just spitballing here. Is this worth exploring?

","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

Good point. I've updated the docs according to mention this pitfall

","upvoteCount":0,"url":"https://github.com/chakra-ui/zag/discussions/2801#discussioncomment-14840040"}}}
Discussion options

You must be logged in to vote

Good point. I've updated the docs according to mention this pitfall

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@segunadebayo
Comment options

Answer selected by segunadebayo
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
Converted from issue

This discussion was converted from issue #2798 on October 26, 2025 13:18.