From 27ef2ad0d4dc5c7903b5cea98a438ff6bd161885 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Thu, 12 Oct 2017 13:33:18 -0300 Subject: [PATCH] Find label based on value --- client/coral-ui/components/Dropdown.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/coral-ui/components/Dropdown.js b/client/coral-ui/components/Dropdown.js index aa5e73415..84b1d9139 100644 --- a/client/coral-ui/components/Dropdown.js +++ b/client/coral-ui/components/Dropdown.js @@ -66,10 +66,13 @@ class Dropdown extends React.Component { } renderLabel() { - if (this.props.label) { - return this.props.label; - } else if (this.props.value) { - return this.props.value; + const options = React.Children.toArray(this.props.children); + const option = options.find((option) => option.props.value === this.props.value); + + if (option.label) { + return option.label; + } else if(option.value) { + return option.value; } else { return this.props.placeholder; } @@ -102,7 +105,6 @@ Dropdown.propTypes = { icon: PropTypes.string, onChange: PropTypes.func.isRequired, children: PropTypes.node.isRequired, - label: PropTypes.string, value: PropTypes.oneOfType([ PropTypes.number, PropTypes.string,