Skip to content

Commit

Permalink
fix(input): added hover and focus to input when label placement is ou…
Browse files Browse the repository at this point in the history
…tside-left #2328 (#2958)

* fix(range-calendar): hide only dates outside the month #2890

* fix(range-calendar): corrected spelling mistake in changeset description

* fix(range-calendar): corrected capitalization in changeset description

* fix(input): added hover and focus to input when label placement is outside-left #2328

* fix(input): label props mergeProps precedence change

---------

Co-authored-by: shrinidhi.upadhyaya <shrinidhi.upadhyaya@stud.uni-bamberg.de>
  • Loading branch information
ShrinidhiUpadhyaya and shrinidhi.upadhyaya authored Sep 7, 2024
1 parent 324fd6d commit 985c2e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-schools-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/input": patch
---

Fixed hover and focus of input when label placement is outside-left (#2328)
24 changes: 18 additions & 6 deletions packages/components/input/src/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML

const {isHovered, hoverProps} = useHover({isDisabled: !!originalProps?.isDisabled});

const {isHovered: isLabelHovered, hoverProps: labelHoverProps} = useHover({
isDisabled: !!originalProps?.isDisabled,
});

const {focusProps: clearFocusProps, isFocusVisible: isClearButtonFocusVisible} = useFocusRing();

const {focusWithinProps} = useFocusWithin({
Expand Down Expand Up @@ -307,7 +311,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
"data-focus-visible": dataAttr(isFocusVisible),
"data-readonly": dataAttr(originalProps.isReadOnly),
"data-focus": dataAttr(isFocused),
"data-hover": dataAttr(isHovered),
"data-hover": dataAttr(isHovered || isLabelHovered),
"data-required": dataAttr(originalProps.isRequired),
"data-invalid": dataAttr(isInvalid),
"data-disabled": dataAttr(originalProps.isDisabled),
Expand All @@ -326,6 +330,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
isFilled,
isFocused,
isHovered,
isLabelHovered,
isInvalid,
hasHelper,
hasLabel,
Expand All @@ -349,11 +354,10 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
return {
"data-slot": "label",
className: slots.label({class: classNames?.label}),
...labelProps,
...props,
...mergeProps(labelProps, labelHoverProps, props),
};
},
[slots, labelProps, classNames?.label],
[slots, isLabelHovered, labelProps, classNames?.label],
);

const getInputProps: PropGetter = useCallback(
Expand Down Expand Up @@ -404,7 +408,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
return {
ref: inputWrapperRef,
"data-slot": "input-wrapper",
"data-hover": dataAttr(isHovered),
"data-hover": dataAttr(isHovered || isLabelHovered),
"data-focus-visible": dataAttr(isFocusVisible),
"data-focus": dataAttr(isFocused),
className: slots.inputWrapper({
Expand All @@ -422,7 +426,15 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
},
};
},
[slots, isHovered, isFocusVisible, isFocused, inputValue, classNames?.inputWrapper],
[
slots,
isHovered,
isLabelHovered,
isFocusVisible,
isFocused,
inputValue,
classNames?.inputWrapper,
],
);

const getInnerWrapperProps: PropGetter = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/theme/src/components/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const input = tv({
base: "flex-row items-center flex-nowrap data-[has-helper=true]:items-start",
inputWrapper: "flex-1",
mainWrapper: "flex flex-col",
label: "relative text-foreground pr-2 rtl:pr-0 rtl:pl-2",
label: "relative text-foreground pr-2 rtl:pr-0 rtl:pl-2 pointer-events-auto",
},
inside: {
label: "text-tiny cursor-text",
Expand Down

0 comments on commit 985c2e1

Please sign in to comment.