Skip to content
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

Fix a11y problems on star rating component #2035

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ac3b095
Add aria-label attribute
MewenLeHo May 15, 2023
1382ce2
Update migration guide
MewenLeHo May 15, 2023
d0a53bc
Update color values
MewenLeHo May 16, 2023
cfc26f4
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo May 22, 2023
5497de9
Add new svg for normal size
MewenLeHo May 22, 2023
b798952
Merge branch 'main-mlh-fix-a11y-star-rating' of https://github.com/Or…
MewenLeHo May 22, 2023
3d4d655
Update after specs meeting
MewenLeHo May 23, 2023
bd9eae2
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo May 23, 2023
908d74b
Add small svg and small mixin
MewenLeHo May 23, 2023
7370011
Add readonly and disabled state
MewenLeHo May 23, 2023
2b66a8c
Fix jobs
MewenLeHo May 23, 2023
1f66fec
Fix bundlewatch
MewenLeHo May 24, 2023
c8a7f43
Fix a11y
MewenLeHo May 24, 2023
f892ea1
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo May 24, 2023
58e1db0
Update migration guide
MewenLeHo May 24, 2023
43bc461
Improve a11y disabled state
MewenLeHo May 26, 2023
9b160ad
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jun 6, 2023
00862dc
Change fill color for dark variant
MewenLeHo Jun 6, 2023
4c17a5d
Merge branch 'main-mlh-fix-a11y-star-rating' of https://github.com/Or…
MewenLeHo Jun 6, 2023
37b4f48
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jun 9, 2023
a8153b5
Fix
MewenLeHo Jun 9, 2023
162c728
Fix migration guide
MewenLeHo Jun 9, 2023
1e6f619
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jun 12, 2023
622fb8a
Fix migration guide
MewenLeHo Jun 12, 2023
45abcc9
Fix viewbox
MewenLeHo Jun 12, 2023
5b31c2b
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jun 27, 2023
2b9aad1
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jun 27, 2023
ef47e71
Wording
MewenLeHo Jun 27, 2023
9351ae3
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jul 4, 2023
24f625b
Change variables names in mixin for more transparency
MewenLeHo Jul 4, 2023
6b3d845
Fix small viewbox
MewenLeHo Jul 4, 2023
172e9c3
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jul 24, 2023
775337b
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Jul 27, 2023
3385cd5
Fix bundlewatch
MewenLeHo Jul 27, 2023
42a6ac1
Merge branch 'main' into main-mlh-fix-a11y-star-rating
MewenLeHo Aug 1, 2023
796f3f7
Fix after LMP review
MewenLeHo Aug 1, 2023
683e4e2
Fix bundlewatch
MewenLeHo Aug 1, 2023
e253bb6
Fix
MewenLeHo Aug 4, 2023
ed54f89
Add new design for disabled states light and dark
MewenLeHo Aug 7, 2023
a69c126
Fix
MewenLeHo Aug 8, 2023
707033c
Fix bundlewatch
MewenLeHo Aug 8, 2023
a25657d
.
MewenLeHo Aug 8, 2023
f15d864
.
MewenLeHo Aug 9, 2023
3960fb4
.
MewenLeHo Aug 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 61 additions & 21 deletions scss/forms/_star-rating.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@
//

.star-rating {
&.disabled,
&:disabled {
pointer-events: none;
}

louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
> label {
> label,
span {
display: block;
float: left;
width: 1em;
height: 1em;
font-size: $form-star-size;
cursor: pointer;
@include form-star-rating($accessible-orange);
@include form-star-rating($accessible-orange, $accessible-orange);

&:not(:first-of-type){
margin-left: $form-star-margin-between;
}
}

> input:checked ~ label {
@include form-star-rating($gray-500);
> input:checked ~ label,
span {
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
@include form-star-rating($gray-700, $white);
}

> input:checked + label {
@include form-star-rating($accessible-orange);
> input:checked + label,
.checked {
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
@include form-star-rating($accessible-orange, $accessible-orange);
}

> [data-focus-visible-added]:focus + label {
Expand All @@ -37,44 +36,85 @@
}

&:hover input + label {
@include form-star-rating($black);
@include form-star-rating($black, $black);
}

> input:hover ~ label {
@include form-star-rating($gray-500);
@include form-star-rating($gray-700, $white);
}

> input:hover + label {
@include form-star-rating($black);
@include form-star-rating($black, $black);
}

&.disabled,
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
&:disabled {
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
pointer-events: none;

> label {
@include form-star-rating($gray-700, $gray-700);
}

> input:checked ~ label {
@include form-star-rating($gray-500, $gray-500);
}

> input:checked + label {
@include form-star-rating($gray-700, $gray-700);
}
}
}

.star-rating-dark {
> label {
@include form-star-rating($brand-orange);
@include form-star-rating($brand-orange, $brand-orange);
}

> input:checked ~ label {
@include form-star-rating($gray-700);
@include form-star-rating($gray-500, $black);
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
}

> input:checked + label {
@include form-star-rating($brand-orange);
@include form-star-rating($brand-orange, $brand-orange);
}

&:hover input + label {
@include form-star-rating($white);
@include form-star-rating($white, $white);
}

> input:hover ~ label {
@include form-star-rating($gray-700);
@include form-star-rating($gray-500, $black);
}

> input:hover + label {
@include form-star-rating($white);
@include form-star-rating($white, $white);
}
}

.star-rating-sm > label {
font-size: $form-star-size-sm;
.star-rating-sm {

> label {
font-size: $form-star-size-sm;
@include form-star-rating-sm($accessible-orange, $accessible-orange);
}

> input:checked ~ label {
@include form-star-rating-sm($gray-700, $white);
}

> input:checked + label {
@include form-star-rating-sm($accessible-orange, $accessible-orange);
}

&:hover input + label {
@include form-star-rating-sm($black, $black);
}

> input:hover ~ label {
@include form-star-rating-sm($gray-700, $white);
}

> input:hover + label {
@include form-star-rating-sm($black, $black);
}
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 6 additions & 2 deletions scss/mixins/_star-rating.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// scss-docs-start form-star-rating-mixin
@mixin form-star-rating($color) {
background-image: escape-svg(url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25'><path fill='#{$color}' d='m12.5 2.9 2.379 7.35 7.721-.007-6.25 4.536 2.392 7.346-6.242-4.547-6.242 4.547 2.392-7.346-6.25-4.536 7.721.007Z'/></svg>"));
@mixin form-star-rating($path-color, $fill-color) {
background-image: escape-svg(url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25'><path fill='#{$fill-color}' fill-rule='evenodd' stroke='#{$path-color}' d='m12.5 4.523 2.016 6.227 6.542-.005-5.296 3.843 2.027 6.224L12.5 16.96l-5.289 3.852 2.027-6.224-5.296-3.843 6.542.005L12.5 4.523Z'/></svg>"));
}

@mixin form-star-rating-sm($path-color, $fill-color) {
background-image: escape-svg(url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path fill='#{$fill-color}' fill-rule='evenodd' stroke='#{$path-color}' d='M10 3.943 11.54 8.7l4.998-.004-4.046 2.936 1.548 4.755L10 13.444l-4.04 2.943 1.548-4.755-4.046-2.936L8.46 8.7 10 3.943Z'/></svg>"));
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
}
// scss-docs-end form-star-rating-mixin
64 changes: 42 additions & 22 deletions site/content/docs/5.3/forms/checks-radios.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,19 @@ Star rating system is built on top of radios. Simply add `.star-rating` to a `<f
<legend class="visually-hidden">Results relevance</legend>

<input type="radio" id="terrible" name="rating" value="1" class="visually-hidden">
<label for="terrible" title="Terrible"></label>
<label for="terrible" title="Terrible"><span class="visually-hidden">Terrible</span></label>

<input type="radio" id="bad" name="rating" value="2" class="visually-hidden">
<label for="bad" title="Bad"></label>
<label for="bad" title="Bad"><span class="visually-hidden">Bad</span></label>

<input type="radio" id="mixed" name="rating" value="3" class="visually-hidden">
<label for="mixed" title="Mixed"></label>
<label for="mixed" title="Mixed"><span class="visually-hidden">Mixed</span></label>

<input type="radio" id="good" name="rating" value="4" class="visually-hidden" checked>
<label for="good" title="Good"></label>
<label for="good" title="Good"><span class="visually-hidden">Good</span></label>

<input type="radio" id="excellent" name="rating" value="5" class="visually-hidden">
<label for="excellent" title="Excellent"></label>
<label for="excellent" title="Excellent"><span class="visually-hidden">Excellent</span></label>
</fieldset>
</form>
{{< /example >}}
Expand All @@ -395,19 +395,19 @@ Star ratings come with a smaller variant: `.star-rating-sm`.
<legend class="visually-hidden">Results relevance</legend>

<input type="radio" id="terrible2" name="rating" value="1" class="visually-hidden">
<label for="terrible2" title="Terrible"></label>
<label for="terrible2" title="Terrible"><span class="visually-hidden">Terrible</span></label>

<input type="radio" id="bad2" name="rating" value="2" class="visually-hidden">
<label for="bad2" title="Bad"></label>
<label for="bad2" title="Bad"><span class="visually-hidden">Bad</span></label>

<input type="radio" id="mixed2" name="rating" value="3" class="visually-hidden">
<label for="mixed2" title="Mixed"></label>
<label for="mixed2" title="Mixed"><span class="visually-hidden">Mixed</span></label>

<input type="radio" id="good2" name="rating" value="4" class="visually-hidden" checked>
<label for="good2" title="Good"></label>
<label for="good2" title="Good"><span class="visually-hidden">Good</span></label>

<input type="radio" id="excellent2" name="rating" value="5" class="visually-hidden">
<label for="excellent2" title="Excellent"></label>
<label for="excellent2" title="Excellent"><span class="visually-hidden">Excellent</span></label>
</fieldset>
</form>
{{< /example >}}
Expand All @@ -422,45 +422,65 @@ Add `.star-rating-dark` to the `.star-rating` for a dark variant.
<legend class="visually-hidden">Results relevance</legend>

<input type="radio" id="terrible3" name="rating" value="1" class="visually-hidden">
<label for="terrible3" title="Terrible"></label>
<label for="terrible3" title="Terrible"><span class="visually-hidden">Terrible</span></label>

<input type="radio" id="bad3" name="rating" value="2" class="visually-hidden">
<label for="bad3" title="Bad"></label>
<label for="bad3" title="Bad"><span class="visually-hidden">Bad</span></label>

<input type="radio" id="mixed3" name="rating" value="3" class="visually-hidden">
<label for="mixed3" title="Mixed"></label>
<label for="mixed3" title="Mixed"><span class="visually-hidden">Mixed</span></label>

<input type="radio" id="good3" name="rating" value="4" class="visually-hidden" checked>
<label for="good3" title="Good"></label>
<label for="good3" title="Good"><span class="visually-hidden">Good</span></label>

<input type="radio" id="excellent3" name="rating" value="5" class="visually-hidden">
<label for="excellent3" title="Excellent"></label>
<label for="excellent3" title="Excellent"><span class="visually-hidden">Excellent</span></label>
</fieldset>
</form>
{{< /example >}}

### Readonly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird to have it here since it's not the same behavior and not the same purpose. Do you think we should have a proper section for this component (I mean the whole star rating) ?

Copy link
Contributor Author

@MewenLeHo MewenLeHo Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a good thing yes since we now have normal/small versions + light/dark versions + disabled state + readonly state etc. It's probably too much for a simple section in the Checks & radios page.

In addition the disabled state is supposed to be used outside of a form, in a card for instance, so there is no reason to keep it in the Forms section although the rest of the star rating thing is still a form element. 🤔

Should we split it? (🤢)

Make star ratings readable but non editable by using `<span>` instead of `<input>` elements.

{{< example >}}
<div class="star-rating">
<p class="visually-hidden">Star rating: rated 3 out of 5</p>

<div aria-hidden="true">
<span class="checked"></span>
<span class="checked"></span>
<span class="checked"></span>
<span></span>
<span></span>
</div>
MewenLeHo marked this conversation as resolved.
Show resolved Hide resolved

MewenLeHo marked this conversation as resolved.
Show resolved Hide resolved
</div>
{{< /example >}}

### Disabled

Make star ratings look inactive inside or outside a form by adding the `disabled` boolean attribute to the `<fieldset>` element and the `checked` boolean attribute to any `<input>` element.

{{< example >}}
<fieldset class="star-rating" disabled>
<fieldset class="star-rating" disabled aria-hidden="true">
<legend class="visually-hidden">Disabled star rating</legend>

<input type="radio" id="terrible4" name="rating" value="1" class="visually-hidden">
<label for="terrible4" title="Terrible"></label>
<label for="terrible4" title="Terrible"><span class="visually-hidden">Terrible</span></label>

<input type="radio" id="bad4" name="rating" value="2" class="visually-hidden">
<label for="bad4" title="Bad"></label>
<label for="bad4" title="Bad"><span class="visually-hidden">Bad</span></label>

<input type="radio" id="mixed4" name="rating" value="3" class="visually-hidden" checked>
<label for="mixed4" title="Mixed"></label>
<label for="mixed4" title="Mixed"><span class="visually-hidden">Mixed</span></label>

<input type="radio" id="good4" name="rating" value="4" class="visually-hidden">
<label for="good4" title="Good"></label>
<label for="good4" title="Good"><span class="visually-hidden">Good</span></label>

<input type="radio" id="excellent4" name="rating" value="5" class="visually-hidden">
<label for="excellent4" title="Excellent"></label>
<label for="excellent4" title="Excellent"><span class="visually-hidden">Excellent</span></label>
</fieldset>
<span class="visually-hidden">rated 3 stars out of 5</span>
<p class="visually-hidden">Disabled star rating: rated 3 out of 5</p>
{{< /example >}}

<!-- End mod -->
Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/5.3/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ Please use Boosted v5.3.2 to have the dark mode available.

- <span class="badge bg-success">New</span> Our range documentation now provides an example which displays the current selected value for better usability, but with some extra JavaScript code.

- <span class="badge bg-success">New</span> Star rating has been slightly changed for accessibility purpose; a visually hidden `span` matching the title attribute was added and color contrast of inactive stars has been updated. Please reflect this modification into your websites. Our documentation also includes a disabled and a readonly state for this form element.
```diff
- <label for="excellent" title="Excellent"></label>
+ <label for="excellent" title="Excellent"><span class="visually-hidden">Excellent</span></label>
```

### Helpers and utilities

- <span class="badge bg-success">New</span> `.border-{color}-subtle`.
Expand Down
Loading