From 85ca19586f5143da0fa8bb4e1235a3a99cd2f3a8 Mon Sep 17 00:00:00 2001 From: Ryan Oglesby Date: Wed, 29 Nov 2017 09:01:02 -0800 Subject: [PATCH] feat(select): Add an unselectable placeholder --- src/components/Select/Select.jsx | 14 ++++++++++++-- src/components/Select/__tests__/Select.spec.jsx | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/Select/Select.jsx b/src/components/Select/Select.jsx index 3dac4f1906..f4c31eb64b 100644 --- a/src/components/Select/Select.jsx +++ b/src/components/Select/Select.jsx @@ -14,7 +14,7 @@ import formFieldStyles from '../FormFields.modules.scss' import positionStyles from '../Position.modules.scss' import iconWrapperStyles from '../Icons/IconWrapper.modules.scss' -const Select = ({ options, ...props }) => ( +const Select = ({ options, placeholder, ...props }) => ( {({ className, ...selectProps }, showIcon, feedback) => (
@@ -22,6 +22,11 @@ const Select = ({ options, ...props }) => ( {...selectProps} className={joinClassNames(className, styles.select, formFieldStyles.height)} > + {placeholder && ( + + )} {options.map(({ text, value }) => ( + ) + }) + it('can have an error message', () => { const { select } = doMount({ id: 'some-id', error: 'Oh no a terrible error!' }) @@ -336,10 +346,10 @@ describe('Select', () => { }) it('passes additional attributes to the select element', () => { - const { findSelectElement } = doMount({ name: 'a name', placeholder: 'a placeholder' }) + const { findSelectElement } = doMount({ name: 'a name', id: 'the-id' }) expect(findSelectElement()).toHaveProp('name', 'a name') - expect(findSelectElement()).toHaveProp('placeholder', 'a placeholder') + expect(findSelectElement()).toHaveProp('id', 'the-id') }) it('does not allow custom CSS', () => {