From 9443a9418e5c0d4b92b9d89a3f80235c03d9e335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20=C3=87ivici?= Date: Tue, 31 Oct 2017 15:49:42 +0300 Subject: [PATCH] Docs for SelectButton --- src/showcase/listbox/ListBoxDemo.js | 6 ++ src/showcase/selectbutton/SelectButtonDemo.js | 58 ++++++++++++++----- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/showcase/listbox/ListBoxDemo.js b/src/showcase/listbox/ListBoxDemo.js index eece89c61e..ba4afb6a6d 100644 --- a/src/showcase/listbox/ListBoxDemo.js +++ b/src/showcase/listbox/ListBoxDemo.js @@ -219,6 +219,12 @@ carTemplate(option) { null An array of objects to display as the available options. + + optionLabel + string + null + Name of the label field of an option when an arbitrary objects instead of SelectItems are used as options. + itemTemplate function diff --git a/src/showcase/selectbutton/SelectButtonDemo.js b/src/showcase/selectbutton/SelectButtonDemo.js index ad9baac685..6a6e98a820 100644 --- a/src/showcase/selectbutton/SelectButtonDemo.js +++ b/src/showcase/selectbutton/SelectButtonDemo.js @@ -65,31 +65,51 @@ import {SelectButton} from 'primereact/components/selectbutton/SelectButton';

Getting Started

-

SelectButton requires a value, collection of options with label-value pairs and an onChange event to provide the selected value.

+

SelectButton requires a value to bind and a collection of options. There are two alternatives of how to define the options property; One way is providing a collection of SelectItem instances having label-value pairs + whereas other way is providing an array of arbitrary objects along with the optionLabel property to specify the field name of the option. SelectItem API is designed to have more + control on how the options are displayed such as grouping and disabling however in most cases an arbitrary object collection will suffice.

+ +

Options as SelectItems

+ + {` +var citySelectItems = [ + {label: 'New York', value: 'NY'}, + {label: 'Rome', value: 'RM'}, + {label: 'London', value: 'LDN'}, + {label: 'Istanbul', value: 'IST'}, + {label: 'Paris', value: 'PRS'} +]; + +`} + {` - this.setState({val: event.value})}> + this.setState({val: event.value})}> `} - +

Options as any type

+ {` -constructor(props) { - super(props); - this.state = { - val: null - }; - - this.options = [ - {label: 'Apartment', value: 'Apartment'}, - {label: 'House', value: 'House'}, - {label: 'Studio', value: 'Studio'} - ]; -} +var cities = [ + {name: 'New York', code: 'NY'}, + {name: 'Rome', code: 'RM'}, + {name: 'London', code: 'LDN'}, + {name: 'Istanbul', code: 'IST'}, + {name: 'Paris', code: 'PRS'} +]; + `} + + +{` + this.setState({val: event.value})}> + +`} +

Multiple

SelectButton allows selecting only one item by default and setting multiple option enables choosing more than one item. In multiple case, model property should be an array.

@@ -124,12 +144,18 @@ constructor(props) { null Value of the component. - + options array null An array of objects to display as the available options. + + optionLabel + string + null + Name of the label field of an option when an arbitrary objects instead of SelectItems are used as options. + tabIndex string