-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Replace :hover CSS pseudo class with useHover hook #775
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
Conversation
This is awesome work! Looks like you've got the right idea. 👍 |
@devongovett |
@@ -62,6 +62,7 @@ function SearchField(props: SpectrumSearchFieldProps, ref: RefObject<TextFieldRe | |||
return ( | |||
<TextFieldBase | |||
{...otherProps} | |||
isHovered={isHovered} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can TextFieldBase handle isHovered so that we don't need to get it from useSearchField or apply it in SearchField? I imagine this would help cover TextArea/Textfield
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I'm gonna fix it to use useHover
by itself.
However, If I am right, SearchInput needs to pass isHovered
down to TextFieldBase since it's search-icon needs hover styling as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the search icon is just passed to TextFieldBase, which should handle applying the hovered style to any icon it gets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snowystinger
Oh, I see, and it would be great!
But to look at CSS, I think TextField itself doesn't handle its icon's hovered style but SearchField does.
So I'm thinking about adding some CSS for TextField.
/* current */
.spectrum-Search-input {
/* The value of color is identical for hover/active/focus-ring, but we repeat it here in case one is changed in the future */
&:hover {
& ~ .spectrum-Search-icon {
color: var(--spectrum-search-icon-color-hover);
}
}
&:active {
& ~ .spectrum-Search-icon {
color: var(--spectrum-search-icon-color-down);
}
}
&:focus-ring {
& ~ .spectrum-Search-icon {
color: var(--spectrum-search-icon-color-key-focus);
}
}
&:disabled {
& ~ .spectrum-Search-icon {
color: var(--spectrum-textfield-text-color-disabled);
}
}
}
/* case 1 */
.spectrum-Textfield-input {
&:hover {
& ~ .spectrum-Textfield-icon {
color: var(--spectrum-textfield-placeholder-text-color-hover);
}
}
}
/* case 2 */
.spectrum-Textfield-icon {
color: var(--spectrum-textfield-icon-color);
&.disabled {
color: var(--spectrum-textfield-text-color-disabled);
}
&:hover {
color: var(--spectrum-textfield-placeholder-text-color-hover);
}
}
I prefer case 1 to case 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O thanks for pointing that out. It seems like it's a mistake we have not to put the icon styles completely into the basetextfield given that it'd affect textarea/textfield/searchfield. We can address that later, should allow us to get rid of the spectrum-Search-icon class. Don't worry about it here. Thanks for looking into it!
#790
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
…m into replace-hover
#775 (comment)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look great, thanks for adding those
@@ -62,6 +62,7 @@ function SearchField(props: SpectrumSearchFieldProps, ref: RefObject<TextFieldRe | |||
return ( | |||
<TextFieldBase | |||
{...otherProps} | |||
isHovered={isHovered} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the search icon is just passed to TextFieldBase, which should handle applying the hovered style to any icon it gets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I'll wait for @devongovett to look at it again as well since he was also commenting on it
…-spectrum into so99ynoodles-replace-hover
…o so99ynoodles-replace-hover # Conflicts: # packages/@react-spectrum/tabs/package.json # packages/@react-spectrum/tabs/src/Tab.tsx
Thanks @so99ynoodles! This is great work. I adjusted two things:
|
Closes #771
✅ Pull Request Checklist:
📝 Test Instructions:
I added some tests for
useHover
for its newly created stateisHovered
.Since it was created for visual changes, tests focus on visual changes.
🧢 Your Project:
Components