Socket
Socket
Sign inDemoInstall

react-bootstrap-country-select

Package Overview
Dependencies
30
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-bootstrap-country-select

A country select component with flag icons for React Bootstrap.


Version published
Weekly downloads
238
decreased by-0.83%
Maintainers
1
Install size
1.05 MB
Created
Weekly downloads
 

Readme

Source

React Bootstrap Country Select   Tweet

License: MIT NPM version Required react version Issues npm bundle size

A country select component with flag icons for React Bootstrap.

Go to the demos page to see it in action.

React Bootstrap Country Select screenshot showing country select component when focused React Bootstrap Country Select screenshot showing country select component with entered text and auto suggestions in dropdown below input React Bootstrap Country Select screenshot showing selected country

Installation

yarn add react-bootstrap-country-select

or

npm install react-bootstrap-country-select

Prerequisites

React Bootstrap must be installed and the Bootstrap CSS imported (or included).

Usage

In your index.js or similar:

import 'bootstrap/dist/css/bootstrap.css'; // or include from a CDN
import 'react-bootstrap-country-select/dist/react-bootstrap-country-select.css';

Your component:

import React, { useState } from 'react';
import CountrySelect from 'react-bootstrap-country-select';

const MyComponent = () => {

  const [ value, setValue ] = useState(null); 

  return (
    <CountrySelect
      value={value}
      onChange={setValue}
    />
  );

};

Features

  • Compatible with React Bootstrap v1.0.0+ and Bootstrap 4;
  • Implemented using standard React Bootstrap components;
  • Autosuggest: a list of matching countries is displayed when the input text changes;
  • Country data is provided;
  • Specific countries can be excluded and additional countries added;
  • Country flag icons;
  • onChange and onTextChange callbacks;
  • Custom sort and country list formatter functions;
  • Bootstrap small (sm) and large (lg) sizes are supported
  • Aligns horizontally with Bootstrap form controls;

Options (as React props)

PropertyTypeDefaultDescription
valueobject | stringThe current value: a country object, country ID or null. See valueAs.
onChangefunctionA callback fired when a country is selected or unselected. The argument is the country object, country ID or null.
onTextChangefunctionA callback fired when the input text changes. The first argument is the text value and the second argument is the input's change event object.
countriesarrayAn array of country objects used to populate the country list. Provide this if you'd like to use your own countries data. A country object has the properties: id, name, flag, alpha2, alpha3 and ioc.
exclusionsarrayAn array of country IDs that defines the countries to be excluded from the country list.
additionsarrayAdditional countries in the same format as countries.
valueAsobject | idobjectDetermines if value is a country object or an ID string.
flagsbooleantrueFlags are displayed when true and not displayed when false.
flushbooleantrueWhen true the selected country flag appears in the input. When false it is rendered using <InputGroup.Text/>.
disabledbooleanfalseDisables the country select.
placeholderstring"Type or select country..."Placeholder text displayed in empty input.
noMatchesTextstring"No matches"The text displayed when no countries match the entered input text.
size'sm' | 'lg'Input size variants, for compatibility with other Bootstrap form components.
listMaxHeightnumberMaximum pixel height of the list overlay.
sortfunctionA custom sort function that determines the order of the country list. The function's two arguments country objects.
matchNameFromStartbooleantrueIf true autosuggest matches country names from the start of the string.
matchAbbreviationsbooleanfalseIf true autosuggest matches against alpha2, alpha3 and IOC abbreviations in addition to country names.
countryLabelFormatterfunctionA custom country list item formatter. The argument is a country object.
throwInvalidValueErrorbooleanfalseIf true an error is thrown if the provided value does not match a country.

| formControlProps | object | | Properties applied to the <FormControl/> input. | | overlayProps | object | | Properties applied to the overlay <div> element that contains the country list. | | classPrefix | string | 'country-select' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized CSS. |

For further documentation and live examples visit the website.

If you have a usage query or feature request please create an issue.

License

Copyright (c) 2020 Jason Wilson

MIT License

Keywords

FAQs

Last updated on 22 Jul 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc