Typeahead is auto suggestion or completion based on what the user is starting to type, gets refined as the user types more.
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "Colors", name: :foo, is_multi: false }) %> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-default-result-option-select", function(event) { console.log('Single Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-default-result-clear", function() { console.log('All options cleared') }) <% end %>
Grouped options can be rendered via structuring the options in the way shown in the code snippet below.
<% grouped_options = [ { label: "Warm Colors", options: [ { label: "Red", value: "#FF0000" }, { label: "Orange", value: "#FFA500" }, { label: "Yellow", value: "#FFFF00" }, { label: "Coral", value: "#FF7F50" }, { label: "Gold", value: "#FFD700" } ] }, { label: "Cool Colors", options: [ { label: "Blue", value: "#0000FF" }, { label: "Teal", value: "#008080" }, { label: "Cyan", value: "#00FFFF" }, { label: "Navy", value: "#000080" }, { label: "Turquoise", value: "#40E0D0" } ] }, { label: "Neutrals", options: [ { label: "White", value: "#FFFFFF" }, { label: "Black", value: "#000000" }, { label: "Gray", value: "#808080" }, { label: "Beige", value: "#F5F5DC" }, { label: "Silver", value: "#C0C0C0" } ] }, { label: "Earth Tones", options: [ { label: "Brown", value: "#A52A2A" }, { label: "Olive", value: "#808000" }, { label: "Forest Green", value: "#228B22" }, { label: "Tan", value: "#D2B48C" }, { label: "Maroon", value: "#800000" } ] }, { label: "Fun Shades", options: [ { label: "Pink", value: "#FFC0CB" }, { label: "Magenta", value: "#FF00FF" }, { label: "Lime", value: "#00FF00" }, { label: "Purple", value: "#800080" }, { label: "Indigo", value: "#4B0082" } ] } ] %> <br /> <%= pb_rails("typeahead", props: { id: "typeahead-custom-options", options: grouped_options, label: "Colors", name: :foo, placeholder: "Select a Color...", is_multi: false }) %>
The optional default_options prop can be used to set a default value for the kit. When a default value is set, focus will be automatically set to the selected option and the dropdown container will scroll to bring the selected option into view.
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#1e3d1eff' }, { label: 'Blue', value: '#0000FF' }, { label: 'Purple', value: '#800080' }, { label: 'Yellow', value: '#FFFF00' }, { label: 'Pink', value: '#FFC0CB' }, { label: 'Brown', value: '#A52A2A' }, { label: 'Black', value: '#000000' }, { label: 'White', value: '#FFFFFF' }, { label: 'Gray', value: '#808080' }, { label: 'Cyan', value: '#00FFFF' }, { label: 'Magenta', value: '#FF00FF' }, { label: 'Lime', value: '#00FF00' }, { label: 'Maroon', value: '#800000' }, { label: 'Olive', value: '#808000' }, { label: 'Navy', value: '#000080' }, { label: 'Teal', value: '#008080' }, { label: 'Silver', value: '#C0C0C0' }, { label: 'Gold', value: '#FFD700' }, { label: 'Beige', value: '#F5F5DC' }, { label: 'Coral', value: '#FF7F50' } ] %> <% grouped_options = [ { label: "Warm Colors", options: [ { label: "Red", value: "#FF0000" }, { label: "Orange", value: "#FFA500" }, { label: "Yellow", value: "#FFFF00" }, { label: "Coral", value: "#FF7F50" }, { label: "Gold", value: "#FFD700" } ] }, { label: "Cool Colors", options: [ { label: "Blue", value: "#0000FF" }, { label: "Teal", value: "#008080" }, { label: "Cyan", value: "#00FFFF" }, { label: "Navy", value: "#000080" }, { label: "Turquoise", value: "#40E0D0" } ] }, { label: "Neutrals", options: [ { label: "White", value: "#FFFFFF" }, { label: "Black", value: "#000000" }, { label: "Gray", value: "#808080" }, { label: "Beige", value: "#F5F5DC" }, { label: "Silver", value: "#C0C0C0" } ] }, { label: "Earth Tones", options: [ { label: "Brown", value: "#A52A2A" }, { label: "Olive", value: "#808000" }, { label: "Forest Green", value: "#228B22" }, { label: "Tan", value: "#D2B48C" }, { label: "Maroon", value: "#800000" } ] }, { label: "Fun Shades", options: [ { label: "Pink", value: "#FFC0CB" }, { label: "Magenta", value: "#FF00FF" }, { label: "Lime", value: "#00FF00" }, { label: "Purple", value: "#800080" }, { label: "Indigo", value: "#4B0082" } ] } ] %> <%= pb_rails("typeahead", props: { default_options: [{ label: 'Gray', value: '#808080' }], id: "typeahead-default-value", options: options, label: "Default Value with basic options", name: :foo, is_multi: false }) %> <%= pb_rails("typeahead", props: { default_options:[{ label: "Pink", value: "#FFC0CB" }], id: "typeahead-default-value-grouped-options", options: grouped_options, label: "Default Value with grouped options", name: :foo, is_multi: false }) %>
<%= pb_rails("select", props: { label: "Colors", name: "foo", data: { context_select: true }, options: [ { value: "red", value_text: "Red" }, { value: "orange", value_text: "Orange" }, { value: "yellow", value_text: "Yellow" }, { value: "green", value_text: "Green" }, { value: "blue", value_text: "Blue" }, { value: "purple", value_text: "Purple" }, ] }) %> <%= pb_rails("typeahead", props: { label: "Crayola Crayons", name: :foo, data: { typeahead_example2: true, search_context_value_selector: "[data-context-select] select" } }) %> <br><br><br> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-search", function(event) { if (!event.target.dataset || !event.target.dataset.typeaheadExample2) return; const fuzzyMatch = function(string, term) { const ratio = 0.5; string = string.toLowerCase(); const compare = term.toLowerCase(); let matches = 0; if (string.indexOf(compare) > -1) return true; for (let index = 0; index < compare.length; index++) { if (string.indexOf(compare[index]) > -1) { matches += 1 } else { matches -=1; } } return (matches / string.length >= ratio || term == "") }; const colors = { red: ["Red", "Scarlet", "Chestnut", "Mahogany"], orange: ["Orange", "Apricot", "Peach", "Melon", "Burnt Sienna", "Macaroni and Cheese"], yellow: ["Yellow", "Gold", "Goldenrod", "Canary", "Laser Lemon"], green: ["Green", "Olive Green", "Granny Smith Apple", "Spring Green", "Sea Green"], blue: ["Blue", "Cerulean", "Bluetiful", "Sky Blue", "Cadet Blue", "Cornflower"], purple: ["Violet", "Indigo", "Wisteria", "Purple Mountain Majesty", "Lavender"] }; event.detail.setResults(colors[event.detail.searchingContext].filter((color) => fuzzyMatch(color, event.detail.searchingFor)).map((color) => document.createTextNode(color))); }) <% end %>
Typeahead kit is data-driven. The minimum default fields are label and value.
This is an example of an option: { label: 'Windows', value: '#FFA500' }
You can also pass default_options which will populate the initial pill selections:
default_options: [{ label: 'Windows', value: '#FFA500' }]
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.
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.
<% options = [ { label: 'Windows', value: '#FFA500' }, { label: 'Siding', value: '#FF0000' }, { label: 'Doors', value: '#00FF00' }, { label: 'Roofs', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-pills-example1", default_options: [options.first], options: options, label: "Products", name: :foo, pills: true }) %> <%= pb_rails("button", props: {id: "clear-pills", text: "Clear All Options", variant: "secondary"}) %> <!-- This section is an example of the available JavaScript event hooks --> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-pills-example1-result-option-select", function(event) { console.log('Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-pills-example1-result-option-remove", function(event) { console.log('Option removed') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-pills-example1-result-clear", function() { console.log('All options cleared') }) document.querySelector('#clear-pills').addEventListener('click', function() { document.dispatchEvent(new CustomEvent('pb-typeahead-kit-typeahead-pills-example1:clear')) }) <% end %>
Use the inputDisplay/input_display prop to optionally display only the count in the display as opposed to multiple pills. This prop is set to 'pills' by default.
NOTE: inputDisplay/input_display should only be used with typeaheads that allow multi selection.
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, { label: 'Yellow', value: '#FFFF00' }, { label: 'Purple', value: '#800080' }, { label: 'Cyan', value: '#00FFFF' }, { label: 'Magenta', value: '#FF00FF' } ] %> <%= pb_rails("typeahead", props: { id: "typeahead-input-display-none", label: "With Input Display None", options: options, name: :foo, input_display: "none", }) %> <br/> <%= pb_rails("typeahead", props: { id: "typeahead-input-display-pills", label: "With Input Display Pills (Default)", options: options, name: :foo, pills: true, }) %>
Passing is_multi: false will allow the user to only select one option from the drop down. Note: this will disable pills prop.
<% options = [ { label: 'Windows', value: '#FFA500' }, { label: 'Siding', value: '#FF0000' }, { label: 'Doors', value: '#00FF00' }, { label: 'Roofs', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-without-pills-example1", placeholder: "All Products", options: options, label: "Products", name: :foo, is_multi: false }) %> <!-- This section is an example of the available JavaScript event hooks --> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-without-pills-example1-result-option-select", function(event) { console.log('Single Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-without-pills-example1-result-clear", function() { console.log('All options cleared') }) <% end %>
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.
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
<%= pb_rails("typeahead", props: { async: true, get_option_label: 'getOptionLabel', get_option_value: 'getOptionValue', load_options: 'asyncPillsPromiseOptions', label: "Github Users", name: :foo, pills: true, placeholder: "type the name of a Github user" }) %> <!-- This section is an example of how to provide load_options prop for using dynamic options --> <%= javascript_tag defer: "defer" do %> // Simple filter function, providing a list of results in the expected data format const filterResults = function(results) { return results.items.map(function(result) { return { name: result.login, id: result.id, } }) } /* Note: Make sure you assign this to window or a namespace within window or it will not be accessible to the kit! */ window.asyncPillsPromiseOptions = function(inputValue) { return new Promise(function(resolve) { if (inputValue) { fetch(`https://api.github.com/search/users?q=${inputValue}`) .then(function(response) { return response.json() }) .then(function(results) { resolve(filterResults(results))}) } else { resolve([]) } }) } window.getOptionLabel = function(option) { return option.name; } window.getOptionValue = function(option) { return option.id; } <% end %>
If the data field imageUrl is present, FormPill will receive that field as a prop and display the image.
<%= pb_rails("typeahead", props: { async: true, load_options: 'asyncPillsPromiseOptionsUsers', label: "Github Users", name: :foo, pills: true, placeholder: "type the name of a Github user" }) %> <%= javascript_tag defer: "defer" do %> const filterUserResults = function(results) { return results.items.map(function(result) { return { imageUrl: result.avatar_url, label: result.login, value: result.id, } }) } window.asyncPillsPromiseOptionsUsers = function(inputValue) { return new Promise(function(resolve) { if (inputValue) { fetch(`https://api.github.com/search/users?q=${inputValue}`) .then(function(response) { return response.json() }) .then(function(results) { resolve(filterUserResults(results))}) } else { resolve([]) } }) } <% end %>
<% synths = [ { label: 'Oberheim', value: 'OBXa' }, { label: 'Moog', value: 'Minimoog' }, { label: 'Roland', value: 'Juno' }, { label: 'Korg', value: 'MS-20' }, ] %> <% cities = [ { label: 'Budapest', value: 'Hungary' }, { label: 'Singapore', value: 'Singapore' }, { label: 'Oslo', value: 'Norway' }, { label: 'Lagos', value: 'Nigeria' }, ] %> <%= pb_rails("typeahead", props: { default_options: [synths.first], id: "typeahead-inline-example1", inline: true, options: synths, label: "Synths", placeholder: "Add synths", pills: true }) %> <%= pb_rails("typeahead", props: { id: "typeahead-inline-example2", inline: true, options: cities, label: "Cities", pills: true, placeholder: "Add cities", plus_icon: true }) %>
<% labels = [ { label: 'Verve', value: '1956' }, { label: 'Stax', value: '1957' }, { label: 'Motown', value: '1959' }, { label: 'Kudu', value: '1971' }, { label: 'Stones Throw', value: '1996' }, ] %> <% expressionists = [ { label: 'Kandinsky', value: 'Russia' }, { label: 'Klee', value: 'Switzerland' }, { label: 'Kokoschka', value: 'Austria' }, { label: 'Kirchner', value: 'Germany' }, ] %> <%= pb_rails("typeahead", props: { default_options: [labels.first], id: "typeahead-multi-kit-example1", options: labels, label: "Badges", multi_kit: "badge", pills: true }) %> <%= pb_rails("typeahead", props: { default_options: [expressionists.first], id: "typeahead-multi-kit-example2", options: expressionists, label: "Small Pills", multi_kit: "smallPill", pills: true }) %>
The createable prop allows users to create new options by typing a value that doesn't exist in the options list.
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-creatable", placeholder: "All Colors", options: options, label: "Colors", name: :foo, createable: true, pills: true, }) %> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-creatable-result-option-select", function(event) { console.log('Single Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-creatable-result-clear", function() { console.log('All options cleared') }) <% end %>
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).
<% options = [ { label: 'Windows', value: '#FFA500' }, { label: 'Siding', value: '#FF0000' }, { label: 'Doors', value: '#00FF00' }, { label: 'Roofs', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-error-example", options: options, error: "Please make a valid selection", label: "Products", name: :foo, is_multi: false }) %> <!-- This section is an example of the available JavaScript event hooks --> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-error-example-result-option-select", function(event) { console.log('Option selected') console.dir(event.detail) }) <% end %>
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "None", name: :foo, is_multi: false, margin_bottom: "none", }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "XXS", name: :foo, is_multi: false, margin_bottom: "xxs", }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "XS", name: :foo, is_multi: false, margin_bottom: "xs", }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "Default - SM", name: :foo, is_multi: false, }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "MD", name: :foo, is_multi: false, margin_bottom: "md", }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "LG", name: :foo, is_multi: false, margin_bottom: "lg", }) %> <%= pb_rails("typeahead", props: { id: "typeahead-default", placeholder: "All Colors", options: options, label: "XL", name: :foo, is_multi: false, margin_bottom: "xl", }) %> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-default-result-option-select", function(event) { console.log('Single Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-default-result-clear", function() { console.log('All options cleared') }) <% end %>
Change the form pill color by passing the optional pill_color prop. Product, Data, and Status colors are available options. Check them out here in the Form Pill colors example.
<% options = [ { label: 'Windows', value: '#FFA500' }, { label: 'Siding', value: '#FF0000' }, { label: 'Doors', value: '#00FF00' }, { label: 'Roofs', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-pills-example2", pill_color: "neutral", options: options, label: "Products", name: :foo, pills: true }) %>
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.
<% names = [ { label: 'Alexander Nathaniel Montgomery', value: 'Alexander Nathaniel Montgomery' }, { label: 'Isabella Anastasia Wellington', value: 'Isabella Anastasia Wellington' }, { label: 'Christopher Maximilian Harrington', value: 'Christopher Maximilian Harrington' }, { label: 'Elizabeth Seraphina Kensington', value: 'Elizabeth Seraphina Kensington' }, { label: 'Theodore Jonathan Abernathy', value: 'Theodore Jonathan Abernathy' }, ] %> <%= pb_rails("typeahead", props: { html_options: { style: { maxWidth: "240px" }}, id: "typeahead-form-pill", is_multi: true, options: names, label: "Truncation Within Typeahead", pills: true, truncate: "1", }) %>
You can also set up a typeahead to render options dynamically based on input from a select. To achieve this:
idsearch_context_selector prop on the typeahead. The value here must match the id of the select so the Typeahead knows where to read the current "context" from.options_by_context to pass in a hash whose keys match the possible values of your “context” select. Each key maps to an array of { label, value } objects. The typeahead automatically displays only the subset of options matching the current context.clear_on_context_change prop controls whether the typeahead clears or not when a change happens in the linked select. This prop is set to true by default so that whenever a selection is made in the select, the Typeahead automatically clears its current input/selection.<%= pb_rails("select", props: { id:"color_context_2", label: "Choose a Color", name: "color_name", options: [ { value: "red", value_text: "Red" }, { value: "blue", value_text: "Blue" }, { value: "green", value_text: "Green" } ], }) %> <%= pb_rails("typeahead", props: { label: "Pick a Shade", is_multi: false, search_context_selector: "color_context_2", options_by_context: { "red": [ { label: "Scarlet", value: "scarlet" }, { label: "Mahogany", value: "mahogany" }, { label: "Crimson", value: "crimson" } ], "blue": [ { label: "Sky Blue", value: "sky" }, { label: "Cerulean", value: "cerulean" }, { label: "Navy", value: "navy" } ], "green": [ { label: "Emerald", value: "emerald" }, { label: "Mint", value: "mint" }, { label: "Olive", value: "olive" } ] }, id: "typeahead-dynamic-options", }) %> <%= javascript_tag defer: "defer" do %> document.addEventListener("pb-typeahead-kit-typeahead-dynamic-options-result-option-select", function(event) { console.log('Single Option selected') console.dir(event.detail) }) document.addEventListener("pb-typeahead-kit-typeahead-dynamic-options-result-clear", function() { console.log('All options cleared') }) <% end %>
The dynamic rendering of options for the typeahead can also be achieved with a pure Rails implementation (not react rendered). For this implementation, use all the props as above with the following additions:
search_term_minimum_length: this sets the minimum input in the typeahead needed to display the dropdown. This is set to 3 by default. Set it to 0 for the dropdown to always display when the typeahead is interacted with. <%= pb_rails("select", props: { id:"color_context", label: "Choose a Color", name: "color_name_2", options: [ { value: "red", value_text: "Red" }, { value: "blue", value_text: "Blue" }, { value: "green", value_text: "Green" } ], }) %> <%= pb_rails("typeahead", props: { label: "Pick a Shade", search_context_selector: "color_context", options_by_context: { "red": [ { label: "Scarlet", value: "scarlet" }, { label: "Mahogany", value: "mahogany" }, { label: "Crimson", value: "crimson" } ], "blue": [ { label: "Sky Blue", value: "sky" }, { label: "Cerulean", value: "cerulean" }, { label: "Navy", value: "navy" } ], "green": [ { label: "Emerald", value: "emerald" }, { label: "Mint", value: "mint" }, { label: "Olive", value: "olive" } ] }, search_term_minimum_length: 0, }) %>
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-disabled", disabled: true, placeholder: "All Colors", options: options, label: "Colors", name: :foo, is_multi: false }) %>
By default, text is not preserved in the typeahead kit when you click off of the input field. You can utilize the preserve_search_input prop in order to prevent text from being cleared when the field loses focus
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-preserve-search-input", is_multi: false, label: "Colors", options: options, placeholder: "Select...", preserve_search_input: true, }) %>
The requiredIndicator/required_indicator prop displays a red asterisk (*) next to the label, visually indicating that the field is required. This is purely visual and does not enforce validation.
You can use requiredIndicator/required_indicator with any validation approach: HTML5 validation via the required prop, client-side validation, or backend validation. For this reason, it works independently and doesn't need to be paired with the required prop.
<% options = [ { label: 'Orange', value: '#FFA500' }, { label: 'Red', value: '#FF0000' }, { label: 'Green', value: '#00FF00' }, { label: 'Blue', value: '#0000FF' }, ] %> <%= pb_rails("typeahead", props: { id: "typeahead-required-indicator", is_multi: false, label: "Colors", options: options, required_indicator: true, }) %>
Avoid using on questionaires, surverys, text input and textarea when users answers/inputs will be individualized.
| Props | Type | Values |
|---|---|---|
align_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_items |
enum | responsive
|
start
end
center
|
border_radius |
enum
|
none
xs
sm
md
lg
xl
rounded
|
cursor |
enum
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
|
dark |
boolean
|
true
false
|
flex |
enum | responsive
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_direction |
enum | responsive
|
row
column
rowReverse
columnReverse
|
flex_wrap |
enum | responsive
|
wrap
nowrap
wrapReverse
|
justify_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
line_height |
enum
|
loosest
looser
loose
normal
tight
tighter
tightest
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
width |
string
|
|
min_width |
string
|
|
max_width |
string
|
|
gap |
string | responsive
|
|
column_gap |
string | responsive
|
|
row_gap |
string | responsive
|
|
number_spacing |
enum
|
tabular
|
order |
enum | responsive
|
none
first
1
2
3
4
5
6
7
8
9
10
11
12
|
overflow_x |
enum
|
scroll
visible
hidden
auto
|
overflow_y |
enum
|
scroll
visible
hidden
auto
|
overflow |
enum
|
scroll
visible
hidden
auto
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
position |
enum
|
relative
absolute
fixed
sticky
static
|
shadow |
enum
|
none
deep
deeper
deepest
|
text_align |
enum | responsive
|
start
end
left
right
center
justify
justifyAll
matchParent
|
truncate |
enum
|
none
1
2
3
4
5
|
vertical_align |
enum | responsive
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
z_index |
enum | responsive
|
1
2
3
4
5
6
7
8
9
10
max
|
top |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
inset |
boolean
|
true
false
|
right |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
bottom |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
left |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
height |
string
|
|
max_height |
string
|
|
min_height |
string
|
|
hover |
object
|
|
group_hover |
boolean
|
true
false
|
| Props | Type | Values | Default |
|---|---|---|---|
async |
boolean
|
true
false
|
false
|
components |
genericobject
|
||
createable |
boolean
|
true
false
|
false
|
disabled |
boolean
|
true
false
|
false
|
error |
string
|
||
input_display |
enum
|
pills
none
|
pills
|
label |
string
|
||
load_options |
string | noop
|
||
get_option_label |
string | (() => string)
|
||
get_option_value |
string | (() => string)
|
||
name |
string
|
||
options |
array
|
||
on_change |
any
|
||
options_by_context |
record<string, array<{label: string; value?: string}>>
|
||
required |
boolean
|
true
false
|
false
|
required_indicator |
boolean
|
true
false
|
false
|
validation |
genericobject
|
||
search_context_selector |
string
|
||
clear_on_context_change |
boolean
|
true
false
|
true
|
preserve_search_input |
boolean
|
true
false
|
false
|
default_options |
array
|
||
inline |
boolean
|
true
false
|
false
|
multi_kit |
string
|
||
input_options |
string
|
||
is_multi |
boolean
|
true
false
|
true
|
pills |
boolean
|
true
false
|
false
|
placeholder |
string
|
||
plus_icon |
boolean
|
true
false
|
false
|
search_term_minimum_length |
string
|
3
|
|
search_debounce_timeout |
string
|
250
|
|
value |
string
|
||
pill_color |
enum
|
primary
neutral
success
warning
error
info
data_1
data_2
data_3
data_4
data_5
data_6
data_7
data_8
windows
siding
roofing
doors
gutters
solar
insulation
accessories
|
primary
|
wrapped |
boolean
|
true
false
|
false
|