fix(rating): address inconsistent hover behavior#3196
Conversation
🦋 Changeset detectedLatest commit: eaf9568 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
🚀 Deployed on https://pr-3196--spectrum-css.netlify.app |
File metricsSummaryTotal size: 4.27 MB* Table reports on changes to a package's main file. Other changes can be found in the collapsed Details section below.
Detailsrating
* Results are not gzipped or minified. * An ASCII character in UTF-8 is 8 bits or 1 byte. |
3a4f7ca to
878ed6c
Compare
There was a problem hiding this comment.
When testing, I'm seeing a couple issues:
-
The focus ring should not be appearing on click. The existing
is-focusedis actually just for keyboard focus.Really
.is-focusedshould be named.is-keyboardFocusedor even better the selector could be&:has(:focus-visible), &.is-keyboardFocused { ... }, though I'm not sure we want to do that sort of renaming now? If we're already doing a breaking change, we could, though I'm hesitant to increase the scope of this work.I'd definitely reword the docs sentence that says "When the rating receives focus" to "When the rating receives keyboard focus".
-
Clicking on any of the ratings on the Docs page doesn't update something with the current value; the underline will show in the wrong place.
-
The
is-hoveredclass gets leftover on elements when Rating is no longer being hovered
| } | ||
| } | ||
|
|
||
| &.is-hovered { |
There was a problem hiding this comment.
The requirement for this class and how it should be used needs to be included in usage notes within the documentation. Within the PR description would be helpful as well.
As I am understanding it, previously CSS would set all stars filled on hover of the whole component, and then all stars following the hovered star unfilled using the subsequent-sibling combinator (~). And that will not work when you hover on the gap between items. And with this change you are looking at having a class that the implementation will apply to the hovered star as well as all previous stars? And those classes should stay until hover or focus leaves the component?
I think that could work. Perhaps this class should be something like .is-hoverSelection? It seems odd to also have is-hovered on elements that aren't actually hovered. It might also be worth adding the hover pseudo to the selector :hover, &.is-hoverSelection.
Another option would be using padding instead of gaps, but I don't know if we want to go that route or not.
There was a problem hiding this comment.
Got it! I'll add this to the PR description and will look for the usage notes.
That is an accurate description of the issue — I first approached it using CSS but there's an issue with one of our postcss plugins when trying to style one of the stars based on the hover state of the next: saulhardman/postcss-hover-media-feature#35.
I've updated the selector to use :hover, .is-hoverSelection. The latter is now removed from all child icons on mouseout of the parent component.
There was a problem hiding this comment.
I've updated is-focused to be is-keyboardFocused and changed the state in the stories and templates too.
Clicking on any of the ratings on the Docs page doesn't update something with the current value; the underline will show in the wrong place.
I need to look at this a bit more — it doesn't look like the instance in the docs is making it into the @change handler that updates this (as it works in the stories for the component):
@change=${function(e) {
const rating = e.target.closest(`.${rootClass}`);
if (!rating) return;
const input = rating.closest(`.${rootClass}-input`);
if (!input) return;
if (!isReadOnly && !isDisabled) {
updateArgs({ value: parseInt(input.value, 10) });
}
}}8470a26 to
610396a
Compare
6147f91 to
f0255e7
Compare
01f2393 to
634d93d
Compare
7bd952c to
6399ea5
Compare
65707f1 to
1ed0669
Compare
238a158 to
d7f1510
Compare
Co-authored-by: Marissa Huysentruyt <69602589+marissahuysentruyt@users.noreply.github.com>
Co-authored-by: Marissa Huysentruyt <69602589+marissahuysentruyt@users.noreply.github.com>
d7f1510 to
eaf9568
Compare
01e3d9f to
9dcf26f
Compare
|
Closing this — going to see if we can lift the hover logic into the S2 migration. #3627 |
Description
Provides more granular control over the hover behavior of child stars within the rating component to prevent hovering in space adjacent to the component from highlighting all stars.
CSS-735
How and where has this been tested?
Verified in local Storybook story for rating component.
Validation steps
Regression testing
Validate:
Screenshots
To-do list