Skip to content

Commit

Permalink
feat(select): add height variations to select (#5311)
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Gonzales <[email protected]>
Co-authored-by: Josh Black <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2020
1 parent 3f30243 commit 6d23a70
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/components/src/components/select/_select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
}
}

.#{$prefix}--select-input--sm {
height: rem(32px);
max-height: rem(32px);
}

.#{$prefix}--select-input--xl {
height: rem(48px);
max-height: rem(48px);
}

.#{$prefix}--select--disabled .#{$prefix}--label,
.#{$prefix}--select--disabled .#{$prefix}--form__helper-text {
color: $disabled-02;
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/Select/Select-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { withKnobs, boolean, text } from '@storybook/addon-knobs';
import { withKnobs, boolean, text, select } from '@storybook/addon-knobs';
import Select from '../Select';
import SelectItem from '../SelectItem';
import SelectItemGroup from '../SelectItemGroup';
import SelectSkeleton from '../Select/Select.Skeleton';

const sizes = {
'Extra large size (xl)': 'xl',
'Regular size (lg)': '',
'Small size (sm)': 'sm',
};

const props = {
select: () => ({
className: 'some-class',
Expand All @@ -23,6 +29,7 @@ const props = {
'Put control in-line with label (inline in <Select>)',
false
),
size: select('Field size (size)', sizes, '') || undefined,
disabled: boolean('Disabled (disabled in <Select>)', false),
hideLabel: boolean('No label (hideLabel in <Select>)', false),
invalid: boolean('Show form validation UI (invalid in <Select>)', false),
Expand Down
13 changes: 12 additions & 1 deletion packages/react/src/components/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Select = React.forwardRef(function Select(
invalidText,
helperText,
light,
size,
...other
},
ref
Expand All @@ -47,6 +48,10 @@ const Select = React.forwardRef(function Select(
[`${prefix}--visually-hidden`]: hideLabel,
[`${prefix}--label--disabled`]: disabled,
});
const inputClasses = classNames({
[`${prefix}--select-input`]: true,
[`${prefix}--select-input--${size}`]: size,
});
const errorId = `${id}-error-msg`;
const error = invalid ? (
<div className={`${prefix}--form-requirement`} id={errorId}>
Expand All @@ -70,7 +75,7 @@ const Select = React.forwardRef(function Select(
{...other}
{...ariaProps}
id={id}
className={`${prefix}--select-input`}
className={inputClasses}
disabled={disabled || undefined}
aria-invalid={invalid || undefined}
ref={ref}>
Expand Down Expand Up @@ -202,6 +207,11 @@ Select.propTypes = {
* select since Pagination renders one for us.
*/
noLabel: PropTypes.bool,

/**
* Specify the size of the Text Input. Currently supports either `sm` or `xl` as an option.
*/
size: PropTypes.oneOf(['sm', 'xl']),
};

Select.defaultProps = {
Expand All @@ -212,6 +222,7 @@ Select.defaultProps = {
invalidText: '',
helperText: '',
light: false,
size: '',
};

export default Select;

0 comments on commit 6d23a70

Please sign in to comment.