Home

Awesome

material-ui-superSelectField

npm javascript style guide downloads
DeepScan Grade Known Vulnerabilities Codecov

Table of Contents

Preview (Live demo)

dataSource caseInsensitive chips

Installation

This component requires 3 peer dependencies :

... so make sure they are installed in your project.

yarn add material-ui-superselectfield

ES5 version

import SelectField from 'material-ui-superselectfield'

ES6+ version

import SelectField from 'material-ui-superselectfield/es'

Properties

NameTypeDefaultDescription
anchorOriginobject{ vertical: 'top', horizontal: 'left' }Anchor position of the menu, accepted values: top, bottom / left, right
autocompleteFilterfunctionsee belowProvide your own filtering parser. Default: case insensitive.<br>The search field will appear only if there are more than 10 children (see showAutocompleteThreshold).<br>By default, the parser will check for label props, 'value' otherwise.
canAutoPositionbooltrueIf present, this property allows the inner Popover component to position the menu in such way options are not hidden by the screen edges.
checkPositionstringPosition of the checkmark in multiple mode. Accepted values: '', left, right
childrenany[]Datasource is an array of any type of nodes, styled at your convenience.<br>/!\ REQUIRED: each node must expose a value property. This value property will be used by default for both option's value and label.<br>A label property can be provided to specify a different value than value.
disabledboolfalseInclude this property to disable superSelectField.
elementHeightnumber, number[]36Height in pixels of each option element. If elements have different heights, you can provide them in an array.
errorTextstring or node''Include this property to show an error warning.
floatingLabelstring or nodeThe content to use for the floating label element.
hintTextstring'Click me'Placeholder text for the main selections display.
hintTextAutocompletestring or node'Type something'Placeholder text for the autocomplete.
keepSearchOnSelectboolfalsePrevents the autocomplete field's value to be reset after each selection.
multipleboolfalseInclude this property to turn superSelectField into a multi-selection dropdown. Checkboxes will appear.
namestringRequired to differentiate between multiple instances of superSelectField in same page.
nb2shownumber5Number of options displayed from the menu.
noMatchFoundnode'No match found'Placeholder text / node when the autocomplete filter fails.
openImmediatelyboolfalseMakes the menu opened on page load.
onAutoCompleteTypingfunction() => {}Exposes the word typed in AutoComplete. Useful for triggering onType API requests.
onChangefunction() => {}Triggers when closing the menu. Use this if you do not want to update your component state with each selection and only on menu close. <br>signature: (selectedValues, name) with selectedValues array of selected values based on selected nodes' value property, and name the value of the superSelectField instance's name property
onMenuOpenfunction() => {}Triggers when opening the Menu.
onSelectfunction() => {}Triggers when selecting an item in the menu. Use this to update your componenet state with each selection from the menu (while still open). <br>signature: (selectedValues, name) with selectedValues array of selected values based on selected nodes' value property, and name the value of the superSelectField instance's name property
showAutocompleteThresholdnumber, 'always', 'never'10Maximum number of options from which to display the autocomplete search field.<br> For example, if autoComplete textfield needs to be disabled, just set this prop with a value higher than children length.<br> However, if you need the autocomplete to show always, you may pass 'always'. This will open the menu even if there are no items to display. Passing 'never' will never show the autocomplete regadless of how many children are passed.
useLayerForClickAwayboolfalseIf true, the popover dropdown will render on top of an invisible layer, which will prevent clicks to the underlying elements, and trigger an onRequestClose('clickAway') call.
valuenull, object, object[]nullSelected value(s).<br>/!\ REQUIRED: each object must expose a 'value' property.
withResetSelectAllButtonsboolfalsePaired with 'multiple', shows an header containing the 'RESET' and 'SELECT ALL' buttons.

Note when setting value

if multiple is set, value must be at least an empty Array.
For single value mode, you can set value to null.
When using objects, make sure they expose a non-null value property.
PropTypes should raise warnings if implementing otherwise.

Styling properties

NameTypeDefaultDescription
autocompleteStyleobjectAllows to change the styles of the auto-complete field (inner input component).<br> Notice: margins left/right and width of the autocomplete root element are not customisable, (automatically calculated)
autocompleteUnderlineStyleobjectAllows to change the styles of the searchTextField's underline.
autocompleteUnderlineFocusStyleobjectAllows to change the styles of the searchTextField's underline when focused.
checkedIconSVGiconsee belowThe SvgIcon to use for the checked state. This is useful to create icon toggles.
dropDownIconSVGiconsee belowThe SvgIcon to use for the drop down icon in the select.
errorStyleobject{color: 'red'}Allows to change the style of error message's container.<br> Will resolve only if errorText is defined.
floatingLabelStyleobjectAllows to change the styles of the floating label.
floatingLabelFocusStyleobjectAllows to change the styles of the floating label when focused.
innerDivStyleobject{}Styles applied to the inner div of MenuItems hosting each of your children components.
hoverColorstring'rgba(69, 90, 100, 0.1)'Overrides the hover background color.
menuStyleobject{}Styles applied to the comtainer which will receive your children components.
menuGroupStyleobject{}Styles applied to the MenuItems hosting your <optgroup/>.
menuFooterStyleobject{}Styles applied to the Menu's footer.
menuCloseButtonnodeA button for an explicit closing of the menu. Useful on mobiles.
noMatchFoundStyleobject{}Allows to change the style of the noMatchFound list item.
popoverClassNamestring''Sets the className property of the Popover component.
popoverWidthnumber180Sets the width of the Menu.<br>The menu is the container for 4 main sub-components: the autocomplete textfield, the header for reset/selectAll buttons, the options container, and the footer.<br>The menu width will always set its width to the highest value between popoverWidth prop(in px) or the root component width. The default value 180px were chosen so that the header's inner buttons don't overflow.
resetButtonnodesee belowNode used to deselect all options.<br>/!\ Requires withResetSelectAllButtons.
selectAllButtonnodesee belowNode used to select all options.<br>/!\ Requires withResetSelectAllButtons.
selectedMenuItemStyleobjectStyles to be applied to the selected MenuItem.
selectionsRendererfunctionsee belowProvide your own renderer for selected options. Defaults to concatenating children's values text. Check CodeExample4 for a more advanced renderer example.
styleobject{}Insert your own inlined styles, applied to the root component.
unCheckedIconSVGiconsee belowThe SvgIcon to use for the unchecked state. This is useful to create icon toggles.
underlineErrorStyleobject{borderColor: 'red'}Allows to change the style of the underline in error state.<br> Will resolve only if errorText is defined.
underlineFocusStyleobjectAllows to change the styles of the underline when focused.
underlineStyleobjectAllows to change the styles of the underline.

Default functions

NameDefault function
autocompleteFilter`(searchText, text) => !text
checkedIcon<CheckedIcon style={{ top: 'calc(50% - 12px)' }} />
dropDownIcon<DropDownArrow/>
resetButton<FlatButton label='reset' hoverColor='rgba(69, 90, 100, 0.1)' fullWidth />
selectAllButton<FlatButton label='select all' hoverColor='rgba(69, 90, 100, 0.1)' fullWidth labelStyle={{ whiteSpace: 'nowrap' }} />
unCheckedIcon<UnCheckedIcon style={{ top: 'calc(50% - 12px)' }} />
selectionsRenderer
<pre>(values, hintText) => { if (!values) return hintText const { value, label } = values if (Array.isArray(values)) { return values.length ? values.map(({ value, label }) => label || value).join(', ') : hintText } else if (label || value) return label || value else return hintText }</pre>

Usage

Check the CodeExampleX.js provided in the repository.

Building

You can build the project with :

git clone https://github.com/Sharlaan/material-ui-superselectfield.git
yarn && yarn start

It should open a new page on your default browser @ localhost:3000

Linking in another local project

To test changes on a local build of SSF :

yarn build && yarn link

... then navigate into your local project directory, and type :

yarn link material-ui-superselectfield

/!\ Warning : if you reinstall dependencies in your project, this will break the link, you will have to re-link SSF.

Tests

yarn test

Contributing

Please follow these steps :

Known bugs

TodoList