Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@opuscapita/react-async-select

OpusCapita119MIT3.0.0

Dropdown component with advanced search modal

readme

react-async-select

Description

This component is a combination of a combobox with asynchronous fetching of results and a modal search dialog for more filtering possibilities.

Installation

npm install @opuscapita/react-async-select

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Prop name Type Default Description
value any | The initially selected value
onSelect function () => {} Selection callback function
loadOptions function () => Promise.resolve([]) Function for fetching options for the combobox
isDisabled boolean false Disables the component from user interaction
localizationTexts object | A dictionary with translated texts as values
localizationTexts.["searchBy"] string | UI text prefix for the first search field
localizationTexts.["by"] string | UI text prefix for other search fields
localizationTexts.["close"] string | UI text for the Close-button
localizationTexts.["select"] string | UI text for the Select-button
localizationTexts.["field.XYZ"] string | Label for the search field with name "XYZ"
localizationTexts.["column.XYZ"] string | Header for the column with name "XYZ"
localizationTexts.["loading"] string 'Loading...' Loading placeholder text
localizationTexts.["noItems"] string '--' Empty result set text for the dropdown
localizationTexts.["noData"] string 'No rows found' Empty result set text for the modal
localizationTexts.["previous"] string 'Previous' Paging text
localizationTexts.["next"] string 'Next' Paging text
localizationTexts.["page"] string 'Page' Paging text
localizationTexts.["of"] string 'of' Paging text
localizationTexts.["rows"] string 'rows' Paging text
localizationTexts.["pageJump"] string 'jump to page' Paging text
localizationTexts.["rowsSelector"] string 'rows per page' Paging text
modal object | Modal dialog specific props
modal.title string '' Localized title of the modal
modal.fields [string] [] List of fields to show as columns
modal.loadOptions function () => Promise.resolve({ data: [], totalCount: 0 }) Function for fetching entries to the table
modal.components object {} A collection of custom components
modal.components.LeftPanel element null Custom component for left side panel
modal.components.RightPanel element null Custom component for right side panel
setRef function () => {} Allows access to select component ref from outside
onKeyDown function () => {} Allows handling of keydown events from outside

Code example

import React, { useState } from 'react';
import { Dropdown } from '@opuscapita/react-component-example';

export default class ReactView extends React.Component {
  const [value, setValue] = useState(null);

  render() {
    return (
      <Dropdown
        localizationTexts={{
          searchBy: 'Search by',
          by: 'By',
          close: 'Close',
          select: 'Select',
          "field.fieldName1": 'my field',
          "field.fieldName2": 'another field'
          "column.fieldName1": 'My field',
          "column.fieldName2": 'Another field',
          "previous": "PREV",
          "next": "NEXT",
          "loading": "LOADING",
          "noData": "NODATA",
          "page": "PAGE",
          "of": "OF",
          "rows": "ROWS",
          "pageJump": "JUMP",
          "rowsSelector": "RPP",
        }}
        isDisabled={false}
        value={value}
        loadOptions={
          () => Promise.resolve([
            { label: 'a_DisplayValue', value: 'a' }
            { label: 'b_DisplayValue', value: 'b' }
          ])
        }
        onSelect={value => setValue(value)}
        modal={{
          title: 'Search entries',
          fields: [
            'fieldName1',
            'fieldName2',
          ],
          loadOptions: () => Promise.resolve({
            data: [
              {
                fieldName1: 'a_DisplayValue',
                fieldName2: 'a_AnotherDisplayValue'
                value: 'a'
              },
              {
                fieldName1: 'b_DisplayValue',
                fieldName2: 'b_AnotherDisplayValue'
                value: 'b'
              },
            ],
            totalCount: 0
          }),
          components: {
            LeftPanel: ({ selectedRow }) => (<div></div>),
            RightPanel: ({ selectedRow }) => (<div></div>),
          }
        }}
      />
    );
  }
}

changelog

Changelog

3.0.0

  • Remove handleChange prop and let the consuming app to determine how values are set

2.6.1

  • Add debounce to data fetching

2.5.2

  • Add missing select highlight to SearchModal

2.5.1

  • Fix Async select, ref > innerRef

2.5.0

  • Add support for setting external ref to select

2.4.3

  • Modify CSS variables to SCSS variables

2.4.2

  • Style and structure improvements

2.4.1

  • Fix sidepanels defined as classes

2.4.0

  • Add custom component for a side panel

2.3.1

  • Fixed destroy -call on an uninitialized Tether component

2.3.0

  • Modified dropdown component to apply tethering on dropdown menu

2.2.1

  • Fixed "loading" translation in react-select
  • Fixed pagination bug in react-table

2.2.0

  • Added localization for the dropdown "No options" text
  • Remove empty lines from modal's result table
  • Fixed overflow styles

2.1.0

  • Added default filtering options
  • Update example.component.jsx to have a working custom changeHandler

2.0.1

  • Fixed double requesting on page switch

2.0.0

  • Updated react-select to v2

1.1.11

  • Add support of custom filters, custom renderers for CELLs

1.0.11

  • Add possibility to localize paging component

1.0.10

  • Provide more space for selected value text

1.0.9

  • Add separate localization fields for column headers

1.0.8

  • Remove border radius from select
  • Add scroll bar to modal content
  • Show paging component on one line

1.0.7

  • Added functionality to disable component

1.0.6

  • Fixed reference error in componentWillReceiveProps lifecycle function

1.0.5

  • Fixed flexbox styles
  • Modify props passing to prevent passing of unnecessary props to react-select
  • Added componentWillReceiveProps lifecycle method to update state based on new props

1.0.4

  • Add customizeability to change handler

1.0.3

  • Fix dependencies

1.0.2

  • Modify value selection to select the entire option object, not only it's value
  • Fixed translation bug in column headings
  • Updated demo

1.0.1

  • Fix modal table updating on input
  • Update README.md

1.0.0

  • Improved localization configurability

0.0.1

  • Initial release