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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悶] Input id can't be undefined #824

Open
ziimakc opened this issue Jun 4, 2024 · 2 comments
Open

[馃悶] Input id can't be undefined #824

ziimakc opened this issue Jun 4, 2024 · 2 comments
Labels
STATUS-1: needs triage This doesn't seem right TYPE: bug Something isn't working

Comments

@ziimakc
Copy link

ziimakc commented Jun 4, 2024

Which package is affected?

Styled Kit

Describe the bug

With exactOptionalPropertyTypes: true typescript config input component id can't be undefined.

To avoid similar issues I would suggest to use strict typescript configuration in repository.

import { $, component$, type PropsOf } from "@builder.io/qwik";
import { cn } from "../../utils/other";

type InputProps = PropsOf<"input"> & {
	error?: string;
};

export const Input = component$<InputProps>(
	({
		name,
		error,
		id,
		["bind:value"]: valueSig,
		value,
		onInput$,
		class: className,
		...props
	}) => {
		const inputId = id || name;  // can't be undefined

		return (
			<>
				<input
					{...props}
					aria-errormessage={`${inputId}-error`}
					aria-invaid={!!error}
					// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
					value={valueSig ? valueSig.value : value}
					onInput$={
						valueSig
							? $((__, el) => (valueSig.value = el.value))
							: onInput$
					}
					class={cn(
						"rounded-base border-input bg-background text-foreground file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-12 w-full border px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50",
						className,
					)}
					id={inputId}
				/>
				{error && (
					<div
						id={`${inputId}-error`}
						class="text-destructive mt-1 text-sm"
					>
						{error}
					</div>
				)}
			</>
		);
	},
);

Reproduction

none

Steps to reproduce

No response

System Info

none

Additional Information

No response

@ziimakc ziimakc added STATUS-1: needs triage This doesn't seem right TYPE: bug Something isn't working labels Jun 4, 2024
@thejackshelton
Copy link
Contributor

@ziimakc did you mean to put headless kit on this issue? there is no headless input component

@thejackshelton
Copy link
Contributor

Ah looks like the styled one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage This doesn't seem right TYPE: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants