Deprecated as of Novemeber 2024. Please use New Library(B_Block v2.0)

DropDown Component

Drop Down component that can be used to render a custom Drop Down and receive input from the user.

Props

PropertyTypeDescription
classNamestringThe CSS class name(s) applied to the dropdown
idanyThe unique identifier for the dropdown
labelstringThe label for the dropdown
namestringThe name of the dropdown
disabledbooleanWhether the dropdown is disabled or not
onChange(event: ChangeEvent<HTMLInputElement>) => voidThe event handler for when the value of the dropdown changes
dataSourceany []The data source for the dropdown options
fieldsobjectThe fields to display in the dropdown options
sortOrderanyThe sort order for the dropdown options
placeholderstringThe placeholder text displayed in the dropdown
allowFilteringbooleanWhether filtering is allowed in the dropdown
popupHeightstringThe height of the popup displaying the dropdown options
autofillbooleanWhether autofill is enabled for the dropdown

Usage

Here's an example of how to use the Drop Down component:

Functional Component
App.tsx
import { useState } from 'react';
import './App.css';
import { DropDown } from 'gbs-building-block';
 
function App() {
  let data = [
    { id: 1, name: 'Discover Music' },
    { id: 2, pid: 1, name: 'Hot Singles' },
    { id: 3, pid: 1, name: 'Rising Artists' },
    { id: 4, pid: 1, name: 'Live Music' },
    { id: 6, pid: 1, name: 'Best of 2017 So Far' },
    { id: 7, name: 'Sales and Events' },
    { id: 8, pid: 7, name: '100 Albums' },
    { id: 9, pid: 7, name: 'Hip-Hop and R&B Sale' },
    { id: 10, pid: 7, name: 'CD Deals' },
  ];
  let fields = { text: 'name', value: 'name' };
 
  // State to store selected data
  const [selectedData, setSelectedData] = useState();
 
  console.log(selectedData);
 
  const handleComboChange = (args: any) => {
    setSelectedData(args.itemData);
  };
 
  return (
    <div className="App">
      <div style={{ width: '12rem' }}>
        <DropDown
          allowFiltering={true}
          dataSource={data}
          fields={fields}
          placeholder="Choose the choosen one"
          id="custom_data"
          name="data_custom"
          autofill={true}
          onChange={handleComboChange}
        />
      </div>
    </div>
  );
}
 
export default App;
Class Component
App.tsx
import React from 'react';
import './App.css';
import { DropDown } from 'gbs-building-block';
 
class App extends React.Component {
  data = [
    { id: 1, name: 'Discover Music' },
    { id: 2, pid: 1, name: 'Hot Singles' },
    { id: 3, pid: 1, name: 'Rising Artists' },
    { id: 4, pid: 1, name: 'Live Music' },
    { id: 6, pid: 1, name: 'Best of 2017 So Far' },
    { id: 7, name: 'Sales and Events' },
    { id: 8, pid: 7, name: '100 Albums' },
    { id: 9, pid: 7, name: 'Hip-Hop and R&B Sale' },
    { id: 10, pid: 7, name: 'CD Deals' },
  ];
 
  fields = { text: 'name', value: 'name' };
 
  state = {
    selectedData: undefined,
  };
 
  handleComboChange = (args) => {
    this.setState({ selectedData: args.itemData });
  };
 
  render() {
    console.log(this.state.selectedData);
 
    return (
      <div className="App">
        <div style={{ width: '12rem' }}>
          <DropDown
            allowFiltering={true}
            dataSource={this.data}
            fields={this.fields}
            placeholder="Choose the choosen one"
            id="custom_data"
            name="data_custom"
            autofill={true}
            onChange={this.handleComboChange}
          />
        </div>
      </div>
    );
  }
}
 
export default App;