Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 5 months ago

Interactive Rating Component

react, tailwind-css
Adnan Iliyasu Muhammad•190
@Adnan0-IM
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Nishanth Venkatesan•1,030
    @nishanth1596
    Posted 5 months ago

    Hi Adnan! Great work!

    Just a couple of suggestions;

    1.        {ratings.map((rating) => {
               return (
                 <button
                   onClick={() => handleclick(rating)}
                   className={`${
                     activeButton === rating &&
                     "bg-neutral-white text-neutral-very-dark-blue"
                   } bg-gray-700 hover:bg-primary-orange   hover:text-neutral-very-dark-blue p-4 sm:p-6 rounded-full size-12 sm:size-14 flex items-center justify-center`}
                   key={rating}
                 >
                   {rating}
                 </button>
               );
             })}
      

    You can simplify it a bit by using an implicit return, like this:

    {ratings.map((rating) => (
      <button
        onClick={() => handleClick(rating)}
        className={`${
          activeButton === rating &&
          "bg-neutral-white text-neutral-very-dark-blue"
        } bg-gray-700 hover:bg-primary-orange hover:text-neutral-very-dark-blue p-4 sm:p-6 rounded-full size-12 sm:size-14 flex items-center justify-center`}
        key={rating}
      >
        {rating}
      </button>
    

    It's just a personal preference to make the code a little cleaner! We coders tend to be a bit lazy, after all. 😊 :P

    1. For the heading “How did we do?”, I would suggest using an <h2> or <h3> tag since this is a small component, it might be better to use a different heading level for accessibility and SEO. You could consider adding a hidden <h1> tag like “Interactive Rating Project” (with the sr-only Tailwind class) to keep the semantic structure intact.

    2. If you are practising react router, then its okay else you can dynamically change the component from Rating to thankyou component based on the few conditions which might improve the user experience a bit more. Also there's a bug, when reloading the page after rating, i am getting page not found error. its related to the path.You can add a go back button page if rating is not given. This happens only when reload the thank you page.

    <h3 className="bg-gray-700 text-primary-orange text-xs sm:text-sm px-3 py-2 font-semibold w-fit mx-auto rounded-full mt-2">You selected {rating} out of 5</h3>
         <h1 className="text-neutral-white text-2xl sm:text-3xl font-medium mt-2">Thank you!</h1>
    

    Typically, it's best to use only one <h1> per page, as it helps with both accessibility and SEO. Headings within the page should follow a logical structure, which ensures the content is well-organized and easily understood by screen readers and search engines.

    In your case, using both <h1> and <h3> together could potentially create issues in terms of HTML structure and accessibility, as it jumps over an expected <h2> and might disrupt the logical flow of headings.

    Instead of using an <h3> here, it would be more appropriate to use a <p> tag, since the text you’re displaying ("You selected {rating} out of 5") doesn’t need to be a heading. This will maintain the proper semantic structure and improve the overall accessibility of the page.

    Keep up the excellent work! You're doing great, and these small tweaks will help enhance both readability and accessibility. 😊

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub