diff --git a/addons/knobs/src/components/__tests__/Select.js b/addons/knobs/src/components/__tests__/Select.js index 464d43f66bd..ccc2e2b0255 100644 --- a/addons/knobs/src/components/__tests__/Select.js +++ b/addons/knobs/src/components/__tests__/Select.js @@ -22,7 +22,7 @@ describe('Select', () => { const green = wrapper.find('option').first(); expect(green.text()).toEqual('Green'); - expect(green.prop('value')).toEqual('#00ff00'); + expect(green.prop('value')).toEqual('Green'); }); }); }); diff --git a/addons/knobs/src/components/types/Select.js b/addons/knobs/src/components/types/Select.js index 4fe654e0e2b..ee49a1a8343 100644 --- a/addons/knobs/src/components/types/Select.js +++ b/addons/knobs/src/components/types/Select.js @@ -1,32 +1,32 @@ -import React, { Component } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { Select } from '@storybook/components'; -class SelectType extends Component { - renderOptionList({ options }) { - if (Array.isArray(options)) { - return options.map(val => this.renderOption(val, val)); - } - return Object.keys(options).map(key => this.renderOption(key, options[key])); - } +const SelectType = ({ knob, onChange }) => { + const { options } = knob; + const entries = Array.isArray(options) + ? options.reduce((acc, k) => Object.assign(acc, { k }), {}) + : options; - renderOption(key, value) { - const opts = { key, value }; + const selectedKey = Object.keys(entries).find(k => entries[k] === knob.value); - return ; - } - - render() { - const { knob, onChange } = this.props; - - return ( - - ); - } -} + return ( + + ); +}; SelectType.defaultProps = { knob: {}, diff --git a/examples/official-storybook/stories/__snapshots__/addon-knobs.stories.storyshot b/examples/official-storybook/stories/__snapshots__/addon-knobs.stories.storyshot index 5b446a426bf..8053f7b4667 100644 --- a/examples/official-storybook/stories/__snapshots__/addon-knobs.stories.storyshot +++ b/examples/official-storybook/stories/__snapshots__/addon-knobs.stories.storyshot @@ -14,7 +14,7 @@ exports[`Storyshots Addons|Knobs.withKnobs accepts story parameters 1`] = ` exports[`Storyshots Addons|Knobs.withKnobs complex select 1`] = `
- string + the type of string = string`; @@ -24,7 +24,7 @@ exports[`Storyshots Addons|Knobs.withKnobs dynamic knobs 1`] = ` I must be here
{value}; + return ( +
+ the type of {value} = {typeof m} ++ ); }) .add('triggers actions via button', () => { button('Toggle item list state', () => {