Skip to content

Commit

Permalink
Merge pull request #97 from nsbno/fix-input-clickability
Browse files Browse the repository at this point in the history
Make input fields easier to focus even without FormControl wrapping
  • Loading branch information
selbekk committed Feb 21, 2022
2 parents f33e8b8 + aaf0b69 commit 011ae8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-owls-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vygruppen/spor-input-react": patch
---

Fix a bug where the label in input fields would get in the way of clicking parts of the input field when not wrapped in a FormControl
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/spor-input-react/src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ export type InputProps = Exclude<ChakraInputProps, "variant" | "size"> & {
* ```
*/
export const Input = forwardRef<InputProps, "input">(
({ label, leftIcon, rightIcon, ...props }, ref) => {
({ label, leftIcon, rightIcon, id, ...props }, ref) => {
const Container = leftIcon || rightIcon ? InputGroup : Box;
return (
<Container position="relative">
{leftIcon && <InputLeftElement>{leftIcon}</InputLeftElement>}
<ChakraInput
pl={leftIcon ? 7 : undefined}
pr={rightIcon ? 7 : undefined}
id={id}
{...props}
ref={ref}
placeholder=" " // This is needed to make the label work as expected
/>
<FormLabel>{label}</FormLabel>
<FormLabel htmlFor={id} pointerEvents="none">
{label}
</FormLabel>
{rightIcon && <InputRightElement>{rightIcon}</InputRightElement>}
</Container>
);
Expand Down

0 comments on commit 011ae8d

Please sign in to comment.