Form Input




Passphrase

Default


Confirmation


Meter Settings


This example shows how to enhance the passphrase strenght by setting diferent thresholds and lengths.

The meterSettings array contains different settings for each rendered input. The handleStrengthCalculation handles the strength calculation using those settings, showing different results for the same passphrase input.

By default, minLength is 12. Try typing any value in the Default Example input. Notice that the bar won't change from red until the minimum is met.

Adjust these props to tune the sensitivity of the bar.

Note: minimum length trumps strength and will set the bar to a red color, despite whatever strength is calculated.

Disclaimer

This example depends on the zxcvbn library.

You can use any library to achieve the same result, this example only intends to show how to add more features to the Passphrase kit.

Input Props


inputProps is passed directly to an underlying Text Input kit. See the specific docs here for more details.

Tips


showTipsBelow(react) / show_tips_below(rails) takes 'xs', 'sm', 'md', 'lg', 'xl' and only show the tips below the given screen size. Similar to the responsive table breakpoints. Omit this prop to always show.

Strength Change


Strength is calculated on a 0-4 scale by the Zxcvbn package.

Disclaimer

This example depends on the zxcvbn library.

You can use any library to achieve the same result, this example only intends to show how to add more features to the Passphrase kit.

Common Passphrases


Disclaimer

This example depends on the zxcvbn library.

You can use any library to achieve the same result, this example only intends to show how to add more features to the Passphrase kit.

Breached Passphrases


Use HaveIBeenPwned's API to check for breached passwords.

As the passphrase is typed, it is checked against more than half a billion breached passwords, to help ensure its not compromised.
Should it fail, the feedback will express the passphrase is too common, prompting the user to change.

This uses their k-Anonymity model, so only the first 5 characters of a hashed copy of the passphrase are sent.

Disclaimer

This example depends on the zxcvbn library and haveibeenpwned API.

You can use any library to achieve the same result, this example only intends to show how to add more features to the Passphrase kit.

Phone Number Input

Default


NOTE: Error state is handled by default, validating length (too long or too short) relative to the selected country’s phone format and enforcing numeric-only values for all countries.

Preferred Countries


Preferred countries will display in the order they are listed with the first country preselected, and all non-preferred countries listed alphabetically below in the remaining dropdown.

Initial Country


Setting an initial country preselects that country within the input as well as the country dropdown.

Only Countries


Limiting countries removes all countries from the dropdown except your selections.

Exclude Countries


Excluding countries removes the selected countries from the dropdown.

Form Validation


Clearing the Input Field


To clear a number inside the input element, create a ref inside your parent component, pass it to the kit's ref prop, and use ref.current.clearField().

clearField() is a custom function inside the kit to clear numbers and the error message while still providing validation.

Accessing the Input Element


To access the kit's input element attributes or add event listeners, create a ref inside your parent component, pass it to the kit's ref prop, and use ref.current.inputNode() with your desired attribute or event listener inside a useEffect hook. useEffect is necessary because the ref will be initially undefined. Calling useEffect with an empty dependency array ensures your event listeners won't be added twice.

inputNode() is a custom function inside the kit that returns the input DOM element and its attributes. For example, to get the name attribute, use ref.current.inputNode().name

Format as You Type


NOTE: the number in the React onChange event will not include formatting (no spaces, dashes, and parentheses). For Rails, the value will include formatting and its value must be sanitized manually.

Strict Mode


Ignore any irrelevant characters and cap the length at the maximum valid number length.

This can be combined with format_as_you_type / formatAsYouType.

Text Input

Default


With Error


Text Input w/ Error shows that the radio option must be selected or is invalid (ie when used in a form it signals a user to fix an error).

Custom


Disabled


Add On


Inline


No Label


Mask


Sanitized Masked Input


When utilizing the Mask prop, you can retrieve the sanitized value of your input through an event handler that targets sanitizedValue.

Rich Text Editor

Default


Advanced Default


The advanced variant leverages Tiptap to unlock additional UI options (e.g., consolidated nav toolbar, styling, etc.) as well as several extensions (see Tiptap docs for more). To leverage this variant, Tiptap must be installed in your project. Complete docs for using the library can be found here. To get started with this variant, see the Code Example below for required imports as well as the basic setup.

NOTE: Once the Tiptap editor is initialized as shown below, you must pass that instance to the kit via the advancedEditor prop.

Advanced (Extra Extensions)


This variant allows you to optionally include any of Tiptap’s 53 extensions within any advanced editor by using the extensions prop.

NOTE: In order to leverage this prop, you must install the extension you need in your project, import it and pass it to the extensions array as shown in this example with the HorizontalRule and the Highlight extensions.

In order to add the extension to the editor toolbar, create an array of objects (as shown in the ExtensionsList array in the example below). Each object in this array should include:

icon: the icon to display within the toolbar dropdown (any Fontawesome icons can be used)
isActive: sets the extension to active within the dropdown, when applicable
text: the label within the toolbar dropdown
onclick: initializes the extension when it’s clicked within the dropdown (snytax varies with extension, see Tiptap's docs for more information)

This array can then be passed to the extensions prop and all extensions in the array will be rendered in the ellipsis dropdown.

Advanced (Toolbar disabled)


Because our default variant's toolbar requires Tiptap's StarterKit which may include features that are not relevant to your project or even block some custom extensions, optionally setting advancedEditorToolbar to false creates an editor without a toolbar, using only the minimum requirements.

NOTE: Omitting the Starter Kit requires that the editor’s default extensions (document, paragraph, and text) must be imported directly from Tiptap or as a custom extensions.

Simple


Attributes


Focus


Sticky


Templates


Toolbar Bottom


Inline


Preview


Advanced Preview


Textarea

Default


Custom Textarea Input


Resize


Textarea w/ Error


Textarea w/ Error shows that the radio option must be selected or is invalid (ie when used in a form it signals a user to fix an error).

Character Counter


Inline


Typeahead

Default


React Hook


You can pass react-hook-form props to the Typeahead kit.

With Highlight


With Pills


Typeahead kit is data-driven. The minimum default fields are label and value.

This is an example of an option: { label: 'Windows', value: '#FFA500' }

Rails: Default Options

You can also pass default_options which will populate the initial pill selections:

default_options: [{ label: 'Windows', value: '#FFA500' }]

Rails: Subscribing to JS Events

JavaScript events are triggered based on actions you take within the kit such as selection, removal and clearing.
This kit utilizes a default id prop named react-select-input. It is highly advised to send your own unique id prop when using this kit to ensure these events do not unintentionally affect other instances of the kit in the same view. The examples below will use the unique id prop named typeahead-pills-example1:

pb-typeahead-kit-typeahead-pills-example1-result-option-select event to perform custom work when an option is clicked.
pb-typeahead-kit-typeahead-pills-example1-result-option-remove event to perform custom work when a pill is clicked.
pb-typeahead-kit-typeahead-pills-example1-result-option-clear event to perform custom work when all pills are removed upon clicking the X.

Rails: Publishing JS Events

The same rule regarding the id prop applies to publishing JS events. The examples below will use the unique id prop named typeahead-pills-example1:

pb-typeahead-kit-typeahead-pills-example1:clear event to clear all options.

With Pills (Async Data)


Rails: Providing the load_options Promise

*Additional required props: * async: true, pills: true

The prop load_options, when used in conjunction with async: true and pills: true, points to a JavaScript function located within the global window namespace. This function should return a Promise which resolves with the list of formatted options as described in prior examples above. This function is identical to the function provided to the React version of this kit. See the code example for more details.

React

loadOptions

*Additional required props: * async: true

As outlined in the react-select Async docs, loadOptions expects to return a Promise that resolves resolves with the list of formatted options as described in prior examples above. See the code example for more details.

getOptionLabel + getOptionValue

If your server returns data that requires differing field names other than label and value

See react-select docs for more information: https://react-select.com/advanced#replacing-builtins

With Pills (Async Data w/ Users)


If the data field imageUrl is present, FormPill will receive that field as a prop and display the image.

With Pills (Async Data w/ Custom Options)


Use valueComponent props to pass your desire custom options. valueComponent will be displayed if present.

Inline


Multi Kit Options


Createable


Createable (+ Async Data)


Error State


Typeahead w/ Error shows that an option must be selected or the selected option is invalid (i.e., when used in a form it signals a user to fix an error).

Custom MenuList


Margin Bottom


With Pills (Custom Color)


Change the form pill color by passing the optional pillColor prop. Product, Data, and Status colors are available options. Check them out here in the Form Pill colors example.

Truncated Text


For Form Pills with longer text, the truncate global prop can be used to truncate the label within each Form Pill. Hover over the truncated Form Pill and a Tooltip containing the text or tag section of the Form Pill will appear. See here for more information on the truncate global prop.

Disabled


Preserve Search Input


By default, text is not preserved in the typeahead kit when you click off of the input field. You can utilize the preserveSearchInput prop in order to prevent text from being cleared when the field loses focus