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

[InputGroup] Automatic id binding if none provided #202

Closed
sifferhans opened this issue May 19, 2023 · 0 comments · Fixed by #234
Closed

[InputGroup] Automatic id binding if none provided #202

sifferhans opened this issue May 19, 2023 · 0 comments · Fixed by #234
Labels
enhancement New feature or request

Comments

@sifferhans
Copy link
Contributor

sifferhans commented May 19, 2023

Describe the solution you'd like

It would be nice if we didn't have to put the same name attribute on both the InputGroup and Input components to get the label connected to the input.

The InputForm component could provide a unique id down to its child and be injected to use there.

export const InputGroupInjectionKey = Symbol('input-group') as InjectionKey<{
	id: string
	// ... possibly other things like `invalid`, `describedBy`
}>

// InputGroup.vue
provide(InputGroupInjectionKey, {
	id // eg. input-group-1k4hfe8sh
})

// Input.vue
const inputGroup = inject(InputGroupInjectionKey, { id: props.name })

This would take the usage of the InputGroup from this:

<form>
	<InputGroup name="name" label="Name">
		<Input name="name" />
	</InputGroup>
</form>

to this:

<form>
	<InputGroup label="Name">
		<Input />
	</InputGroup>
</form>

This is in no way an essential feature, but it would be a nice quality-of-life enhancement in my opinion.
Thank you for this awesome UI library! 🎉

@sifferhans sifferhans added the enhancement New feature or request label May 19, 2023
@sifferhans sifferhans changed the title [InputGroup] Automatic id binding [InputGroup] Automatic id binding if none provided May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant