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

fix(input): Fix left icon not being displayed in the text-input #39

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/form-field/text-input/text-input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Meta, StoryObj } from "@storybook/react";
import React, { useState } from "react";
import { FormField } from "../form-field";
import { SearchIcon } from "../../../icons";

const meta: Meta<typeof FormField.TextInput> = {
title: "Input/TextInput",
Expand All @@ -15,9 +16,11 @@ type Story = StoryObj<typeof FormField.TextInput>;
const TextInputWithHooks = ({
error = false,
disabled = false,
hasLeftIcon = false,
}: {
error?: boolean;
disabled?: boolean;
hasLeftIcon?: boolean;
}) => {
const [value, setValue] = useState("");

Expand All @@ -35,6 +38,7 @@ const TextInputWithHooks = ({
ariaDescribedBy="value-description"
error={error}
disabled={disabled}
LeftIcon={hasLeftIcon ? SearchIcon : undefined}
/>
{error ? <FormField.ErrorMessage>Error message.</FormField.ErrorMessage> : null}
</FormField>
Expand All @@ -57,6 +61,14 @@ export const WithError: Story = {
),
};

export const WithLeftIcon: Story = {
render: () => (
<div className="w-72">
<TextInputWithHooks hasLeftIcon error />
</div>
),
};

export const Disabled: Story = {
render: () => (
<div className="w-72">
Expand Down
6 changes: 3 additions & 3 deletions src/components/form-field/text-input/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const TextInput = ({
<div className={classNames("relative w-full", formFieldGroupStyles)}>
{LeftIcon ? (
<div
className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"
className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 z-10"
aria-hidden="true"
>
<LeftIcon className="text-gray-400 h-4 w-4 fill-neutral-600" />
<LeftIcon className="text-gray-400 h-3.5 w-3.5 fill-neutral-600" />
</div>
) : null}

Expand All @@ -88,7 +88,7 @@ export const TextInput = ({
disabled && "cursor-not-allowed bg-neutral-100 text-neutral-600",
!error &&
!disabled &&
"hover:border-neutral-600 focus:z-10 focus:border-primary-400 focus:ring-2 focus:ring-primary-200",
"hover:border-neutral-600 focus:border-primary-400 focus:ring-2 focus:ring-primary-200",
error && !disabled && "border-danger-500"
)}
disabled={disabled}
Expand Down
Loading