---
title: Select Items to Rank
product: Form Library
description: Your respondents can decide which choice options they would like to rank by dragging the required items into the ranking area. Learn how to configure the select to rank option in your rank order question in no time with this free code example for JavaScript.
framework: React
source: https://surveyjs.io/form-library/examples/select-items-to-rank/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Select Items to Rank (React)

In [default mode](/form-library/examples/add-ranking-question-to-form/), the Ranking question requires that respondents sort all choice options available. This demo shows how to configure a rank order question to enable respondents to filter out unwanted items and only prioritize the items they want.

## Enable Item Selection

To enable item selection, assign `true` to the [`selectToRankEnabled`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#selectToRankEnabled) property. With this setting, the Ranking question displays two areas for ranked and unranked items. To order items, respondents should first drag them from the unranked to the ranked area.

The ranked and unranked areas are positioned next to each other. If you want to display them one above the other, set the [`selectToRankAreasLayout`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#selectToRankAreasLayout) property to `"vertical"`. This example demonstrates both the horizontal and vertical layouts.

## Limit the Number of Selected Choices

If you want to limit the maximum number of choices that respondents can select, assign this number to the [`maxSelectedChoices`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#maxSelectedChoices) property. On reaching the limit, the ranked area stops accepting items. In this demo, the `maxSelectedChoices` property is set to 3.

Similarly, you can use the [`minSelectedChoices`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#minSelectedChoices) property to specify a minimum number of choices. If respondents select fewer choices, the Ranking question displays a validation error. This demo sets the `minSelectedChoices` property to 2.

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
  "elements": [
    {
      "type": "ranking",
      "name": "smartphone-features-horizontal-layout",
      "title": "Please rank the following smartphone features from the most important to the least",
      "isRequired": true,
      "choices": [
        "Long battery life",
        "Plenty of storage capacity",
        "High-quality camera",
        "Powerful CPU",
        "Large screen size",
        "High durability",
        "Low price"
      ],
      "selectToRankEnabled": true,
      "selectToRankAreasLayout": "horizontal",
      "minSelectedChoices": 2,
      "maxSelectedChoices": 3
    },
    {
      "type": "ranking",
      "name": "smartphone-features-vertical-layout",
      "title": "Please rank the following smartphone features from the most important to the least",
      "isRequired": true,
      "choices": [
        "Long battery life",
        "Plenty of storage capacity",
        "High-quality camera",
        "Powerful CPU",
        "Large screen size",
        "High durability",
        "Low price"
      ],
      "selectToRankEnabled": true,
      "selectToRankAreasLayout": "vertical",
      "minSelectedChoices": 2,
      "maxSelectedChoices": 3
    }
  ]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/select-items-to-rank/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/select-items-to-rank/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/select-items-to-rank/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/select-items-to-rank/vanillajs.md)
