Skip to content

Commit

Permalink
Merge pull request qwikifiers#772 from thejackshelton/fix-input
Browse files Browse the repository at this point in the history
fix: input and bind:value
  • Loading branch information
thejackshelton authored May 26, 2024
2 parents eee4557 + 43e3ae7 commit ce7fe44
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .changeset/fast-actors-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export default component$(() => {

- Programmatically toggling the popover is still possible, make sure to put the same id on the `<Popover.Root />` that is passed to the `usePopover` hook. Refer to the docs for more info.

- popover-showing and popover-closing classes have been deprecated. Please use the `data-open` and ``data-closing` attributes instead.

- The `data-open`, `data-closing`, and `data-closed` data attributes have been added to the popover.

#### <Popover.Root />

There is a new root compomnent. Configurable props have been moved to the root component.
Expand Down
6 changes: 5 additions & 1 deletion apps/website/src/routes/docs/styled/input/examples/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ import { component$ } from '@builder.io/qwik';
import { Input } from '~/components/ui';

export default component$(() => {
return <Input type="email" placeholder="Email" />;
return (
<>
<Input type="email" placeholder="Email" value="[email protected]" />
</>
);
});
11 changes: 9 additions & 2 deletions packages/kit-styled/src/components/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$, type PropsOf } from '@builder.io/qwik';
import { component$, useSignal, type PropsOf } from '@builder.io/qwik';
import { cn } from '@qwik-ui/utils';

type InputProps = PropsOf<'input'> & {
Expand All @@ -10,19 +10,26 @@ export const Input = component$<InputProps>(
name,
error,
'bind:value': valueSig,
value,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'bind:checked': checkedSig,
id,
...props
}) => {
const inputId = id || name;
const inputRef = useSignal<HTMLInputElement>();

// TODO: remove this when we can figure out why the optimizer forces you to have a signal rather than conditionally adding the bind:value prop.
const dummySig = useSignal<string | undefined>(value?.toString());

return (
<>
<input
{...props}
aria-errormessage={`${inputId}-error`}
aria-invalid={!!error}
bind:value={valueSig}
bind:value={valueSig ? valueSig : dummySig}
ref={inputRef}
class={cn(
'flex h-12 w-full rounded-base border border-input bg-background px-3 py-1 text-sm text-foreground shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
Expand Down

0 comments on commit ce7fe44

Please sign in to comment.