Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
feat(select): add inputWidth property to control width
Browse files Browse the repository at this point in the history
  • Loading branch information
varl committed Nov 25, 2019
1 parent 85187b9 commit 9eefe22
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MultiSelect = ({
tabIndex,
maxHeight,
inputMaxHeight,
inputWidth,
onChange,
onFocus,
onBlur,
Expand Down Expand Up @@ -98,7 +99,7 @@ const MultiSelect = ({
.root-input {
margin-right: ${spacers.dp4};
flex: 1;
flex: ${inputWidth ? `0 0 ${inputWidth}` : '1'};
}
`}</style>
</div>
Expand Down Expand Up @@ -135,6 +136,7 @@ MultiSelect.defaultProps = {
* @prop {string} [loadingText]
* @prop {string} [maxHeight]
* @prop {string} [inputMaxHeight]
* @prop {string} [inputWidth]
* @prop {string} [noMatchText] - Only required if filterable is true
* @prop {string} [placeholder]
* @prop {string} [prefix]
Expand Down Expand Up @@ -162,6 +164,7 @@ MultiSelect.propTypes = {
loadingText: propTypes.string,
maxHeight: propTypes.string,
inputMaxHeight: propTypes.string,
inputWidth: propTypes.string,
noMatchText: propTypes.requiredIf(
props => props.filterable,
propTypes.string
Expand Down
4 changes: 4 additions & 0 deletions src/MultiSelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MultiSelectField extends React.Component {
validationText,
maxHeight,
inputMaxHeight,
inputWidth,
children,
clearable,
clearText,
Expand Down Expand Up @@ -66,6 +67,7 @@ class MultiSelectField extends React.Component {
tabIndex={tabIndex}
maxHeight={maxHeight}
inputMaxHeight={inputMaxHeight}
inputWidth={inputWidth}
onChange={onChange}
onFocus={onFocus}
onBlur={onBlur}
Expand Down Expand Up @@ -135,6 +137,7 @@ MultiSelectField.defaultProps = {
* @prop {string} [loadingText]
* @prop {string} [maxHeight]
* @prop {string} [inputMaxHeight]
* @prop {string} [inputWidth]
* @prop {string} [noMatchText] - Only required if filterable is true
* @prop {string} [placeholder]
* @prop {string} [prefix]
Expand Down Expand Up @@ -166,6 +169,7 @@ MultiSelectField.propTypes = {
loadingText: propTypes.string,
maxHeight: propTypes.string,
inputMaxHeight: propTypes.string,
inputWidth: propTypes.string,
noMatchText: propTypes.requiredIf(
props => props.filterable,
propTypes.string
Expand Down
5 changes: 4 additions & 1 deletion src/SingleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SingleSelect = ({
tabIndex,
maxHeight,
inputMaxHeight,
inputWidth,
onChange,
onFocus,
onBlur,
Expand Down Expand Up @@ -98,7 +99,7 @@ const SingleSelect = ({
.root-input {
margin-right: ${spacers.dp4};
flex: 1;
flex: ${inputWidth ? `0 0 ${inputWidth}` : '1'};
}
`}</style>
</div>
Expand Down Expand Up @@ -135,6 +136,7 @@ SingleSelect.defaultProps = {
* @prop {string} [loadingText]
* @prop {string} [maxHeight]
* @prop {string} [inputMaxHeight]
* @prop {string} [inputWidth]
* @prop {string} [noMatchText] - Only required if filterable is true
* @prop {string} [placeholder]
* @prop {string} [prefix]
Expand Down Expand Up @@ -162,6 +164,7 @@ SingleSelect.propTypes = {
loadingText: propTypes.string,
maxHeight: propTypes.string,
inputMaxHeight: propTypes.string,
inputWidth: propTypes.string,
noMatchText: propTypes.requiredIf(
props => props.filterable,
propTypes.string
Expand Down
4 changes: 4 additions & 0 deletions src/SingleSelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SingleSelectField extends React.Component {
validationText,
maxHeight,
inputMaxHeight,
inputWidth,
children,
clearable,
clearText,
Expand Down Expand Up @@ -66,6 +67,7 @@ class SingleSelectField extends React.Component {
tabIndex={tabIndex}
maxHeight={maxHeight}
inputMaxHeight={inputMaxHeight}
inputWidth={inputWidth}
onChange={onChange}
onFocus={onFocus}
onBlur={onBlur}
Expand Down Expand Up @@ -135,6 +137,7 @@ SingleSelectField.defaultProps = {
* @prop {string} [loadingText]
* @prop {string} [maxHeight]
* @prop {string} [inputMaxHeight]
* @prop {string} [inputWidth]
* @prop {string} [noMatchText] - Only required if filterable is true
* @prop {string} [placeholder]
* @prop {string} [prefix]
Expand Down Expand Up @@ -166,6 +169,7 @@ SingleSelectField.propTypes = {
loadingText: propTypes.string,
maxHeight: propTypes.string,
inputMaxHeight: propTypes.string,
inputWidth: propTypes.string,
noMatchText: propTypes.requiredIf(
props => props.filterable,
propTypes.string
Expand Down
18 changes: 18 additions & 0 deletions stories/MultiSelect.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,21 @@ storiesOf('MultiSelect', module)
{options}
</MultiSelect>
))
.add('Input width', () => (
<MultiSelect
{...defaultProps}
selected={[
{ value: '1', label: 'one' },
{ value: '2', label: 'two' },
{ value: '3', label: 'three' },
{ value: '4', label: 'four' },
{ value: '5', label: 'five' },
{ value: '6', label: 'six' },
{ value: '7', label: 'seven' },
{ value: '8', label: 'eight' },
]}
inputWidth="200px"
>
{options}
</MultiSelect>
))
11 changes: 11 additions & 0 deletions stories/MultiSelectField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ storiesOf('MultiSelectField', module)
{options}
</MultiSelectField>
))
.add('Set width', () => (
<MultiSelectField
{...defaultProps}
helpText="A helpful text."
validationText="Hm, not quite, I warn thee! Consider yourself warned!"
inputWidth="200px"
warning
>
{options}
</MultiSelectField>
))
10 changes: 10 additions & 0 deletions stories/SingleSelect.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,13 @@ storiesOf('SingleSelect', module)
<SingleSelectOption key="2" value="2" label="two" />
</SingleSelect>
))
.add('Input width', () => (
<SingleSelect
{...defaultProps}
selected={{ value: '1', label: longLabel }}
inputWidth="200px"
>
<SingleSelectOption key="1" value="1" label={longLabel} />
<SingleSelectOption key="2" value="2" label="two" />
</SingleSelect>
))
11 changes: 11 additions & 0 deletions stories/SingleSelectField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ storiesOf('SingleSelectField', module)
{options}
</SingleSelectField>
))
.add('Set width', () => (
<SingleSelectField
{...defaultProps}
helpText="A helpful text."
validationText="NO! TOTALLY WRONG! SO EPICALLY WRONG! WHY ARE YOU SO WRONG ALL THE TIME?"
error
inputWidth="200px"
>
{options}
</SingleSelectField>
))

0 comments on commit 9eefe22

Please sign in to comment.