Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-likert-scale

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-likert-scale

A React component that makes a Likert Scale for collecting data.

  • 3.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
551
decreased by-27.4%
Maintainers
1
Weekly downloads
 
Created
Source

React Likert Scale

A React component that makes a Likert Scale for collecting data or to make a survey. It has the following features:

  • it is fully responsive (looks great on laptops and phones)
  • has a very small size (less than 4kb)
  • has zero-dependencies
  • the styling can be customized by providing your own CSS styles

Screenshot of Likert component

Installation

npm i react-likert-scale

Usage

import React from 'react';
import Likert from 'react-likert-scale';

export default () => {
  const likertOptions = {
    question: "What is your opinion of the President’s performance?",
    responses: [
      { value: 1, text: "Abysmal" },
      { value: 2, text: "Poor" },
      { value: 3, text: "Average" },
      { value: 4, text: "Good" },
      { value: 5, text: "Excellent" }
    ],
    onChange: val => {
      console.log(val);
    }
  };
  return (
    <Likert {...likertOptions} />
  )
}

Likert Props

This component has three props:

  • question — (string) This is the prompt that displays above the options.
  • responses — (array of objects) These are your options. The value key is what is returned to the calling application in the onChange callback.
  • onChange — (callback function) Optionally, you can provide a callback function that returns the value of the option that was clicked.

FAQ

How do I change colors or other CSS styling?

The top-level DOM element that gets created by this component is <fieldset class="likertScale">. You can override any styles by prefixing your rule with fieldset.likertScale. For example, let’s say you want the radio button “dots” to have a light gray background with a dark green ring.

fieldset.likertScale .likertIndicator {
  border: thin solid darkGreen;
  background-color: lightGray;
}

I need access to the DOM element created by React. How is that done?

This isn’t very common, but you may want to set focus on a Likert Scale after the page renders. This is done with React via refs. Either create your ref with React.createRef() or the useRef() hook. You can then pass your ref to the Likert component.

import React, { useRef } from 'react';
import Likert from 'react-likert-scale';

export default () => {
  const likertOptions = {
    question: "What is your opinion of the President’s performance?",
    responses: [
      { value: 1, text: "Abysmal" },
      { value: 2, text: "Poor" },
      { value: 3, text: "Average" },
      { value: 4, text: "Good" },
      { value: 5, text: "Excellent" }
    ]
  };

  const likertRef = useRef();

  return (
    <Likert {...likertOptions} ref={likertRef} />
  )
}

Can I pass in DOM attributes such as id, class, disabled, data-*, onClick, etc.?

Sure. They will be applied to the likert component’s top-level DOM element, <fieldset>.

<Likert {...likertOptions}
  id='Q1'
  className='myClass'
  onClick={() => {
    doThis();
    andThis();
  }}
/>

It doesn’t work. What now?

Let me know. Create an issue on GitHub.

Keywords

FAQs

Package last updated on 23 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc