Skip to content

Commit

Permalink
My turn
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 26, 2017
1 parent 46ae7c2 commit 5ac72b2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/Select/SelectInput.d.ts
Expand Up @@ -2,19 +2,19 @@ import * as React from 'react';
import { StyledComponent } from '..';

export interface SelectInputProps {
autoWidth?: boolean,
disabled?: boolean,
native: boolean,
multiple: boolean,
MenuProps?: Object,
name?: string,
autoWidth: boolean;
disabled?: boolean;
native: boolean;
multiple: boolean;
MenuProps?: Object;
name?: string;
onBlur?: React.FocusEventHandler<any>;
onChange?: (event: React.ChangeEvent<{}>, child: React.ReactNode) => void,
onFocus?: React.FocusEventHandler<any>;
readOnly?: boolean,
renderValue?: Function,
selectRef?: Function,
value?: string | number | Array<string | number>,
readOnly?: boolean;
renderValue?: Function;
selectRef?: Function;
value?: string | number | Array<string | number>;
}

declare const SelectInput: StyledComponent<SelectInputProps>;
Expand Down
4 changes: 2 additions & 2 deletions src/Select/SelectInput.js
Expand Up @@ -14,7 +14,7 @@ export type Props = {
* If true, the width of the popover will automatically be set according to the items inside the
* menu, otherwise it will be at least the width of the select input.
*/
autoWidth?: boolean,
autoWidth: boolean,
/**
* The option elements to populate the select with.
* Can be some `MenuItem` when `native` is false and `option` when `native` is true.
Expand Down Expand Up @@ -308,7 +308,7 @@ class SelectInput extends React.Component<AllProps, State> {
}

const minimumMenuWidth =
this.state.anchorEl != null && !autoWidth ? this.state.anchorEl.clientWidth : 0;
this.state.anchorEl != null && !autoWidth ? this.state.anchorEl.clientWidth : undefined;

return (
<div className={classes.root}>
Expand Down
45 changes: 42 additions & 3 deletions src/Select/SelectInput.spec.js
Expand Up @@ -6,7 +6,7 @@ import { spy } from 'sinon';
import { ReactWrapper } from 'enzyme';
import keycode from 'keycode';
import { createShallow, createMount } from '../test-utils';
import { MenuItem } from '../Menu';
import Menu, { MenuItem } from '../Menu';
import consoleErrorMock from '../../test/utils/consoleErrorMock';
import SelectInput from './SelectInput';

Expand All @@ -17,6 +17,7 @@ describe('<SelectInput />', () => {
classes: {
select: 'select',
},
autoWidth: false,
value: 10,
native: false,
multiple: false,
Expand Down Expand Up @@ -66,15 +67,31 @@ describe('<SelectInput />', () => {

describe('prop: MenuProps', () => {
it('should apply additional properties to the Menu component', () => {
const wrapper = mount(
const wrapper = shallow(
<SelectInput
{...props}
MenuProps={{
transitionDuration: 100,
}}
/>,
);
assert.strictEqual(wrapper.find('Menu').props().transitionDuration, 100);
assert.strictEqual(wrapper.find(Menu).props().transitionDuration, 100);
});

it('should be able to override PaperProps minWidth', () => {
const wrapper = shallow(
<SelectInput
{...props}
MenuProps={{
PaperProps: {
style: {
minWidth: 12,
},
},
}}
/>,
);
assert.strictEqual(wrapper.find(Menu).props().PaperProps.style.minWidth, 12);
});
});

Expand Down Expand Up @@ -190,6 +207,28 @@ describe('<SelectInput />', () => {
});
});

describe('prop: autoWidth', () => {
it('should take the anchor width into account', () => {
const wrapper = shallow(<SelectInput {...props} />);
wrapper.setState({
anchorEl: {
clientWidth: 14,
},
});
assert.strictEqual(wrapper.find(Menu).props().PaperProps.style.minWidth, 14);
});

it('should not take the anchor width into account', () => {
const wrapper = shallow(<SelectInput {...props} autoWidth />);
wrapper.setState({
anchorEl: {
clientWidth: 14,
},
});
assert.strictEqual(wrapper.find(Menu).props().PaperProps.style.minWidth, undefined);
});
});

describe('prop: multiple', () => {
before(() => {
consoleErrorMock.spy();
Expand Down

0 comments on commit 5ac72b2

Please sign in to comment.