Skip to content

Commit

Permalink
Rating fixes:
Browse files Browse the repository at this point in the history
- readonly class not added to a "readonly" .rating element, making the stars to grow when hovering
- hovering over a readonly or disabled rating now shows a default cursor, not pointer (since you cannot click on it)
  • Loading branch information
vladrusu committed Oct 16, 2024
1 parent e7330b1 commit c953308
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions js/src/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`

const CLASS_NAME_ACTIVE = 'active'
const CLASS_NAME_DISABLED = 'disabled'
const CLASS_NAME_READONLY = 'readonly'
const CLASS_NAME_RATING = 'rating'
const CLASS_NAME_RATING_ITEM = 'rating-item'
const CLASS_NAME_RATING_ITEM_ICON = 'rating-item-icon'
Expand Down Expand Up @@ -355,6 +356,10 @@ class Rating extends BaseComponent {
this._element.classList.add(CLASS_NAME_DISABLED)
}

if (this._config.readOnly) {
this._element.classList.add(CLASS_NAME_READONLY)
}

this._element.setAttribute('role', 'radiogroup')
Array.from({ length: this._config.itemCount }, (_, index) => this._createRatingItem(index))
}
Expand Down
8 changes: 5 additions & 3 deletions scss/_rating.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

&:not(.disabled):not(.readonly) {
.rating-item {
cursor: pointer;
.rating-item-label {
cursor: pointer;
}

&:hover {
transform: var(--#{$prefix}rating-item-scale-transform);
Expand Down Expand Up @@ -47,7 +49,7 @@
font-size: var(--#{$prefix}rating-item-height);
line-height: 0;
color: var(--#{$prefix}rating-item-color);
cursor: pointer;
cursor: default; // has cursor pointer only if the rating is not disabled or readonly (see above)

* {
pointer-events: none;
Expand Down Expand Up @@ -83,7 +85,7 @@
.rating-item-icon {
width: var(--#{$prefix}rating-item-height);
height: var(--#{$prefix}rating-item-height);
cursor: pointer;
//cursor: pointer; // has the cursor of rating-item-label (parent)
background-color: var(--#{$prefix}rating-item-color);
mask: var(--#{$prefix}rating-item-icon) center / var(--#{$prefix}rating-item-height) no-repeat;
}
Expand Down

0 comments on commit c953308

Please sign in to comment.