Star[Rating] Wars - The MadsAfif Menice [An even better star rating system and a comparison]
Tags: webdev, html, css, javascript
Published: 2021-07-05 13:25:14

In a galaxy...not so far away...two Sith decided to create star rating widgets that were not fully accessible, a part of their devious plan to exclude people and exert control. InHuWan CodeObi is our only hope.

![you are our only hope star wars gif](https://i.imgur.com/CdPl89y.gif)

In an unusual move for the Jedi, InHuWan decided to down his lightsabre and simply produce a hastily written rebuttal piece to educate the galaxy of the evil that had transpired.

Need to catch up on the previous episodes (I would defo read the articles by Mads and Temani if you haven't already!)?

- [my original star rating](https://dev.to/inhuofficial/5-star-rating-system-actually-accessible-no-js-no-wai-aria-3idl)
- [Mads great idea](https://dev.to/madsstoumann/star-rating-using-a-single-input-i0l)
- [Temani with the CSS voodoo](https://dev.to/afif/scalable-star-rating-without-js-and-no-svg-or-image-for-the-star-2mef)

All caught up? Back to the story...

## How the Sith trick you
We do not know which is the master and which is the apprentice, but we know that Darth @afif and Darth @madsstoumann have released propaganda that they have created star rating systems.

But as they use the dark side of the force there are awful problems with both of their "solutions" that continue to exclude people.

### One doesn't even work on iPhone
Darth Afif designed a star rating system that doesn't work on Safari. 

Darth Afif is renowned for using CSS skills that some would deem unnatural, you can learn these skills, but not from a Jedi.

![not from a jedi meme](https://thumbs.gfycat.com/AromaticReasonableGrouper-size_restricted.gif)

Unfortunately as these skills are unnatural they do not work for a large proportion of the population and that doesn't even include the ever forgotten planet of the Internet Explorians

### Neither "solutions" work on Internet Exploria - an often forgotten but important planet
As with many who use the dark side of the force they deliberately exclude those who use older technology, perhaps as they wrongly think they are an inferior race.

Not everyone has the technological know-how to upgrade their browser. Some are even forced to use Internet Explorer as it is the browser that works best with their screen reader.

In fact [12% of people who use a screen reader still rely on Internet Explorer](https://webaim.org/projects/screenreadersurvey8/#browsers) (although that is changing very quickly, the latest results suggest it might be as low as 3.3% 🤞🤞). But the Sith do not concern themselves with such things.

If you happen to have clients in other Countries then you may also want to look at [IE usage in those Countries before ditching it.](https://canistop.net/b/ie/11)

### They do not label their work properly for fear of being discovered.
Darth Afif simply removed the labels from their work in an evil attempt to make it look like they used less HTML.

But without labels our friends over at <b>N</b>i<b>V</b>i<b>D</b>r<b>a</b> and <b>J</b>an<b>A</b>lo<b>W</b>ier<b>S</b>, two little known planets in our Galaxy cannot use this control. 

As for Darth Stoumann - their deceit is a little more subtle.

They wrap their control in a `<label>` in order to make their HTML look neater.

They do not care that [Dragon Naturally Speaking and other voice control software does not work well with implicit labels](https://a11ysupport.io/tech/html/label_element) (wrapping a control in a label) and so he should use an explicit label instead (`for="idofcontrol"`).

### While one removes labels the other uses a less accessible HTML element to further confusion
This is where we start to see some really clever tricks.

Darth Stoumann decided to use an input that is weak with the force.

[Radio buttons have great support (when properly labelled)](https://a11ysupport.io/tech/html/input(type-radio)_element) but [input ranges do not offer the same support](https://a11ysupport.io/tech/html/input(type-range)_element).

Picking a worse element to exclude people is a typical trick of the Sith.

## InHu Wan CodeObi has the solution
His previous attempts at educating the Galaxy failed as his solution required thought. 

Here is a much simplified version that should bring balance to the force and give him the high ground in this conflict.

![Obi Wan "I have the High Ground" meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nkng6qgmqa4z3lglxy14.jpg)

Taking a lot of inspiration from https://bjorn.wikkeling.com/199/pure-css-star-rating.html, there are just a couple of tweaks to the CSS to allow for labels and a proper use of `<fieldset>` and it works beautifully.

{% jsfiddle https://jsfiddle.net/fk3jbhm2/3/ result html css js %}

Now everyone can use this control, even those from Internet Exploria, <b>N</b>i<b>V</b>i<b>D</b>r<b>a</b> and <b>J</b>an<b>A</b>lo<b>W</b>ier<b>S</b>

To make it easier for the custodians of our galaxy (known as "developers") all you have to do with this is add inputs and labels and the CSS takes care of the rest.

{% jsfiddle https://jsfiddle.net/fk3jbhm2/4/ result html css js %}

Or maybe some hearts

{% jsfiddle https://jsfiddle.net/fk3jbhm2/2/ result html css js %}

Or you know what, how about some lightsabres?

{% jsfiddle https://jsfiddle.net/khpxs0vn/ result html css js %}

Credit goes to https://codepen.io/ncerminara/pen/KzurJ for most of the hard work designing.

## Getting the values in JavaScript
The beauty of the above controls is that to get the value is super easy in JavaScript:

``` js
var checked = document.querySelector('input[name=rating]:checked).value;
```

It doesn't get much simpler than that!

## Enough of the silliness
In all honesty @madsstoumann created a great control. 

It may be possible to make it work in IE using `-ms-track`, `-ms-fill-lower` and `-ms-tooltip` but I couldn't work them out using his method. And if he changed his label from an implicit one to an explicit one it is great.

I would probably use his control if you are using React (as you won't support IE anyway) despite the slightly worse support it is still usable by ~98% of people without issues (and those issues will be more of an annoyance than an actual barrier).  

However for ecommerce sites and brochure sites built with HTML, CSS etc. use my version as you may as well have the extra support. 

I would say give it **1 year** and I will finally be able to say "screw IE" to you all. I cannot wait! 

@afif example shows us what the future can hold. We might not be able to use it yet as Safari and IE hold us back, but in a few years when IE does die (because despite the fact I encourage people to support I do want it to die) and browsers all become evergreen it is an exciting prospect! Especially if there is a way to do the same trick but with a range slider.

For now (and not being biased here I promise) I would stick to radio buttons and the above examples in this post. 

You might not like supporting Internet Explorer but as I have done all the work for you why not support it anyway? 

It requires next to no effort from you.

And remember "live long and prosper" (oh wait...is that the wrong franchise?)

![yoda dressed as spock saying "with you, will the force be"](https://pbs.twimg.com/media/CWR7-lPUEAAW2yH.jpg)

## Do you like silly articles like this one?
If you are looking for someone who writes silly articles which occasionally contain useful information:

![hello there obi wan meme](https://media1.tenor.com/images/d35679a70d0b0ea47d541475105285a3/tenor.gif)

Perhaps give me a follow or check out one of my other silly articles such as:

{% post https://dev.to/inhuofficial/13-amazing-tips-for-writing-listicles-5eja %}

or 

{% post https://dev.to/inhuofficial/faang-is-dead-fanmag-was-a-great-idea-but-fanimagment-has-to-be-how-we-describe-big-tech-42jl %}

## We had a late contender in the fight!
As there are only ever two Sith, never more, never less I am guessing @link2twenty has killed either Darth Afif or Dath Stoumann.

Check out his contribution where he also uses unicode characters (but better!) 

{% post https://dev.to/link2twenty/star-rating-using-unicode-stars-3np2 %}