Skip to content

Commit c953308

Browse files
committed
Rating fixes:
- 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)
1 parent e7330b1 commit c953308

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

js/src/rating.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`
3434

3535
const CLASS_NAME_ACTIVE = 'active'
3636
const CLASS_NAME_DISABLED = 'disabled'
37+
const CLASS_NAME_READONLY = 'readonly'
3738
const CLASS_NAME_RATING = 'rating'
3839
const CLASS_NAME_RATING_ITEM = 'rating-item'
3940
const CLASS_NAME_RATING_ITEM_ICON = 'rating-item-icon'
@@ -355,6 +356,10 @@ class Rating extends BaseComponent {
355356
this._element.classList.add(CLASS_NAME_DISABLED)
356357
}
357358

359+
if (this._config.readOnly) {
360+
this._element.classList.add(CLASS_NAME_READONLY)
361+
}
362+
358363
this._element.setAttribute('role', 'radiogroup')
359364
Array.from({ length: this._config.itemCount }, (_, index) => this._createRatingItem(index))
360365
}

scss/_rating.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
&:not(.disabled):not(.readonly) {
2020
.rating-item {
21-
cursor: pointer;
21+
.rating-item-label {
22+
cursor: pointer;
23+
}
2224

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

5254
* {
5355
pointer-events: none;
@@ -83,7 +85,7 @@
8385
.rating-item-icon {
8486
width: var(--#{$prefix}rating-item-height);
8587
height: var(--#{$prefix}rating-item-height);
86-
cursor: pointer;
88+
//cursor: pointer; // has the cursor of rating-item-label (parent)
8789
background-color: var(--#{$prefix}rating-item-color);
8890
mask: var(--#{$prefix}rating-item-icon) center / var(--#{$prefix}rating-item-height) no-repeat;
8991
}

0 commit comments

Comments
 (0)