diff --git a/docs/app/Demos/PowerSelect/ArrayOfObjectsDemo.js b/docs/app/Demos/PowerSelect/ArrayOfObjectsDemo.js
index bf6c2b4..1a461ae 100644
--- a/docs/app/Demos/PowerSelect/ArrayOfObjectsDemo.js
+++ b/docs/app/Demos/PowerSelect/ArrayOfObjectsDemo.js
@@ -1,14 +1,14 @@
import React, { Component } from 'react';
-import PowerSelect from 'src/PowerSelect';
+import { PowerSelect, Option } from 'src';
import { countries } from '../constants';
export default class ArrayOfObjectsDemo extends Component {
state = {
- selectedCountry: null,
+ selectedCountry: 'BRA',
};
- handleChange = ({ option }) => {
- this.setState({ selectedCountry: option });
+ handleChange = ({ value }) => {
+ this.setState({ selectedCountry: value });
};
render() {
@@ -18,10 +18,24 @@ export default class ArrayOfObjectsDemo extends Component {
+ searchIndices={['name']}
+ selectedOptionComponent={({ value }) => {
+ let selectedOption = countries.find(country => country.code === value);
+ return selectedOption.name;
+ }}
+ >
+ {({ results }) => {
+ return results.map(option => {
+ return (
+
+ );
+ });
+ }}
+
);
}
diff --git a/src/DefaultOption.js b/src/DefaultOption.js
new file mode 100644
index 0000000..b7aedda
--- /dev/null
+++ b/src/DefaultOption.js
@@ -0,0 +1,5 @@
+import React, { Component } from 'react';
+
+export default function SelectedOption({ option, select }) {
+ return option;
+}
diff --git a/src/DropdownMenu.js b/src/DropdownMenu.js
index 92faa16..4c1c72a 100644
--- a/src/DropdownMenu.js
+++ b/src/DropdownMenu.js
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import cx from 'classnames';
import { renderComponent } from './utils';
-import Options from './Options';
export default class DropdownMenu extends Component {
componentWillMount() {
@@ -21,6 +20,7 @@ export default class DropdownMenu extends Component {
render() {
let {
+ children,
className,
select,
handleKeyDown,
@@ -43,7 +43,7 @@ export default class DropdownMenu extends Component {
>
{beforeOptionsComponent && renderComponent(beforeOptionsComponent, { select })}
-
+ {children}
{afterOptionsComponent && renderComponent(afterOptionsComponent, { select })}
diff --git a/src/Option.js b/src/Option.js
index 09ddc82..e43f110 100644
--- a/src/Option.js
+++ b/src/Option.js
@@ -1,36 +1,30 @@
import React, { Component } from 'react';
import cx from 'classnames';
-import RenderOption from './RenderOption';
-export default class Option extends Component {
- render() {
- let {
- option,
- select,
- disabled,
- optionIndex,
- optionLabelPath,
- optionComponent,
- isHighlighted,
- onOptionClick,
- } = this.props;
- let isDisabled = disabled || option.disabled;
- return (
-
-
-
- );
- }
+export default function Option({
+ value,
+ disabled,
+ isHighlighted,
+ optionIndex,
+ onOptionClick,
+ children,
+}) {
+ return (
+ {
+ onOptionClick(value);
+ }
+ }
+ >
+ {children}
+
+ );
}
diff --git a/src/Options.js b/src/Options.js
index c6ed9a7..b1aeb91 100644
--- a/src/Options.js
+++ b/src/Options.js
@@ -38,47 +38,67 @@ export default class Options extends Component {
}
}
- renderOptions(options, optGroupDisabled = false) {
- let { select, optionLabelPath, optionComponent, highlightedOption, onOptionClick } = this.props;
- return options.map((option, index) => {
- let optionIndex = getOptionIndex(this.props.options, option);
- if (isOptGroup(option)) {
- return (
-
-
{option.label}
- {this.renderOptions(option.options, option.disabled)}
-
- );
+ // renderOptions(options, optGroupDisabled = false) {
+ // let { select, optionLabelPath, optionComponent, highlightedOption, onOptionClick } = this.props;
+ // return options.map((option, index) => {
+ // let optionIndex = getOptionIndex(this.props.options, option);
+ // if (isOptGroup(option)) {
+ // return (
+ //
+ // {option.label}
+ // {this.renderOptions(option.options, option.disabled)}
+ //
+ // );
+ // }
+ // return (
+ // {
+ // onOptionClick(option);
+ // }}
+ // />
+ // );
+ // });
+ // }
+
+ renderOptions() {
+ let { children, options, highlightedOption, onOptionClick } = this.props;
+ return React.Children.map(children, (child, index) => {
+ let optionIndex = getOptionIndex(options, options[index]);
+ if (child === null) {
+ return null;
+ }
+
+ if (child.type === Option) {
+ return React.cloneElement(child, {
+ ...child.props,
+ isHighlighted: child.props.value === highlightedOption,
+ optionIndex,
+ onOptionClick,
+ });
}
- return (
-