Skip to content

Commit

Permalink
fix: input focus on click (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
floridemai authored Jun 11, 2024
1 parent 98f68d9 commit 5b77354
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
const rightSideComponent = rightSideChild ?? <BsX strokeWidth={0.6} />

return (
<div className={cn(formVariants({ variant }), formClassName)}>
<label className={cn(formVariants({ variant }), formClassName)}>
<div className={cn(leftSideVariants(), leftSideClassName)}>
{leftSideComponent}
</div>
Expand All @@ -121,7 +121,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<button type="button" onClick={onClear} className={rightSideVariants()}>
{rightSideComponent}
</button>
</div>
</label>
)
}
)
Expand Down
8 changes: 3 additions & 5 deletions src/components/Password/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ const Password = React.forwardRef<HTMLInputElement, PasswordProps>(
) => {
const [isMaskOn, setIsMaskOn] = useState(true)

const onToggleMask = () => {
setIsMaskOn(isMaskOn => !isMaskOn)
}
const onToggleMask = () => setIsMaskOn(isMaskOn => !isMaskOn)

return (
<div className={cn(formVariants({ variant }), formClassName)}>
<label className={cn(formVariants({ variant }), formClassName)}>
<input
type={isMaskOn ? 'password' : 'text'}
className={cn(passwordVariants({ variant }), className)}
Expand All @@ -65,7 +63,7 @@ const Password = React.forwardRef<HTMLInputElement, PasswordProps>(
{isMaskOn ? <BsEye /> : <BsEyeSlash />}
</button>
)}
</div>
</label>
)
}
)
Expand Down
14 changes: 7 additions & 7 deletions stories/Input/Docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This component accepts all attributes for the input component of type text, with
import React from 'react'
import { cn } from '@/lib/utils'
import { cva } from 'class-variance-authority'
import { ClearButton, User, SearchOutline } from '@/assets'
import { BsX, BsPersonFill, BsSearch } from '@/assets'

const leftSideVariants = cva(['flex', 'items-center', 'text-inherit'])

Expand Down Expand Up @@ -119,8 +119,8 @@ interface InputProps extends React.HTMLProps<HTMLInputElement> {

const convertTypeToComponent = {
left: {
text: <User />,
search: <SearchOutline />
text: <BsPersonFill />,
search: <BsSearch />
}
}

Expand All @@ -141,10 +141,10 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
) => {
const leftSideComponent =
leftSideChild ?? convertTypeToComponent.left[`${type}`]
const rightSideComponent = rightSideChild ?? <ClearButton />
const rightSideComponent = rightSideChild ?? <BsX strokeWidth={0.6} />

return (
<form className={cn(formVariants({ variant }), formClassName)}>
<label className={cn(formVariants({ variant }), formClassName)}>
<div className={cn(leftSideVariants(), leftSideClassName)}>
{leftSideComponent}
</div>
Expand All @@ -158,12 +158,12 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<button type="button" onClick={onClear} className={rightSideVariants()}>
{rightSideComponent}
</button>
</form>
</label>
)
}
)

export { Input, InputProps }
export { Input, InputProps, formVariants }
```

## Usage
Expand Down
8 changes: 3 additions & 5 deletions stories/Password/Docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ const Password = React.forwardRef<HTMLInputElement, PasswordProps>(
) => {
const [isMaskOn, setIsMaskOn] = useState(true)

const onToggleMask = () => {
setIsMaskOn(isMaskOn => !isMaskOn)
}
const onToggleMask = () => setIsMaskOn(isMaskOn => !isMaskOn)

return (
<div className={cn(formVariants({ variant }), formClassName)}>
<label className={cn(formVariants({ variant }), formClassName)}>
<input
type={isMaskOn ? 'password' : 'text'}
className={cn(passwordVariants({ variant }), className)}
Expand All @@ -98,7 +96,7 @@ const Password = React.forwardRef<HTMLInputElement, PasswordProps>(
{isMaskOn ? <BsEye /> : <BsEyeSlash />}
</button>
)}
</div>
</label>
)
}
)
Expand Down

0 comments on commit 5b77354

Please sign in to comment.