Skip to content

Commit

Permalink
[Select] Follow spec with placement of dropdown icon (#17303)
Browse files Browse the repository at this point in the history
  • Loading branch information
lonssi authored and oliviertassinari committed Sep 4, 2019
1 parent b18a78e commit f4769d0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
4 changes: 3 additions & 1 deletion docs/pages/api/native-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ Any other props supplied will be provided to the root element ([Input](/api/inpu
| <span class="prop-name">outlined</span> | <span class="prop-name">MuiNativeSelect-outlined</span> | Styles applied to the select component if `variant="outlined"`.
| <span class="prop-name">selectMenu</span> | <span class="prop-name">MuiNativeSelect-selectMenu</span> | Styles applied to the select component `selectMenu` class.
| <span class="prop-name">disabled</span> | <span class="prop-name">Mui-disabled</span> | Pseudo-class applied to the select component `disabled` class.
| <span class="prop-name">icon</span> | <span class="prop-name">MuiNativeSelect-icon</span> | Styles applied to the select component `icon` class.
| <span class="prop-name">icon</span> | <span class="prop-name">MuiNativeSelect-icon</span> | Styles applied to the icon component.
| <span class="prop-name">iconFilled</span> | <span class="prop-name">MuiNativeSelect-iconFilled</span> | Styles applied to the icon component if `variant="filled"`.
| <span class="prop-name">iconOutlined</span> | <span class="prop-name">MuiNativeSelect-iconOutlined</span> | Styles applied to the icon component if `variant="outlined"`.

You can override the style of the component thanks to one of these customization points:

Expand Down
4 changes: 3 additions & 1 deletion docs/pages/api/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Any other props supplied will be provided to the root element ([Input](/api/inpu
| <span class="prop-name">outlined</span> | <span class="prop-name">MuiSelect-outlined</span> | Styles applied to the select component if `variant="outlined"`.
| <span class="prop-name">selectMenu</span> | <span class="prop-name">MuiSelect-selectMenu</span> | Styles applied to the select component `selectMenu` class.
| <span class="prop-name">disabled</span> | <span class="prop-name">Mui-disabled</span> | Pseudo-class applied to the select component `disabled` class.
| <span class="prop-name">icon</span> | <span class="prop-name">MuiSelect-icon</span> | Styles applied to the select component `icon` class.
| <span class="prop-name">icon</span> | <span class="prop-name">MuiSelect-icon</span> | Styles applied to the icon component.
| <span class="prop-name">iconFilled</span> | <span class="prop-name">MuiSelect-iconFilled</span> | Styles applied to the icon component if `variant="filled"`.
| <span class="prop-name">iconOutlined</span> | <span class="prop-name">MuiSelect-iconOutlined</span> | Styles applied to the icon component if `variant="outlined"`.

You can override the style of the component thanks to one of these customization points:

Expand Down
6 changes: 4 additions & 2 deletions packages/material-ui/src/NativeSelect/NativeSelect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export interface NativeSelectProps
export type NativeSelectClassKey =
| 'root'
| 'select'
| 'filled'
| 'outlined'
| 'selectMenu'
| 'disabled'
| 'icon'
| 'filled'
| 'outlined';
| 'iconFilled'
| 'iconOutlined';

declare const NativeSelect: React.ComponentType<NativeSelectProps>;

Expand Down
10 changes: 9 additions & 1 deletion packages/material-ui/src/NativeSelect/NativeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const styles = theme => ({
},
/* Pseudo-class applied to the select component `disabled` class. */
disabled: {},
/* Styles applied to the select component `icon` class. */
/* Styles applied to the icon component. */
icon: {
// We use a position absolute over a flexbox in order to forward the pointer events
// to the input.
Expand All @@ -65,6 +65,14 @@ export const styles = theme => ({
color: theme.palette.action.active,
pointerEvents: 'none', // Don't block pointer events on the select under the icon.
},
/* Styles applied to the icon component if `variant="filled"`. */
iconFilled: {
right: 7,
},
/* Styles applied to the icon component if `variant="outlined"`. */
iconOutlined: {
right: 7,
},
});

const defaultInput = <Input />;
Expand Down
18 changes: 14 additions & 4 deletions packages/material-ui/src/NativeSelect/NativeSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { refType } from '@material-ui/utils';
import { capitalize } from '../utils/helpers';

/**
* @ignore - internal component.
*/
const NativeSelectInput = React.forwardRef(function NativeSelectInput(props, ref) {
const { classes, className, disabled, IconComponent, inputRef, variant, ...other } = props;
const {
classes,
className,
disabled,
IconComponent,
inputRef,
variant = 'standard',
...other
} = props;

return (
<React.Fragment>
<select
className={clsx(
classes.root, // TODO v5: merge root and select
classes.select,
classes[variant],
{
[classes.filled]: variant === 'filled',
[classes.outlined]: variant === 'outlined',
[classes.disabled]: disabled,
},
className,
Expand All @@ -26,7 +34,9 @@ const NativeSelectInput = React.forwardRef(function NativeSelectInput(props, ref
ref={inputRef || ref}
{...other}
/>
{props.multiple ? null : <IconComponent className={classes.icon} />}
{props.multiple ? null : (
<IconComponent className={clsx(classes.icon, classes[`icon${capitalize(variant)}`])} />
)}
</React.Fragment>
);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/material-ui/src/Select/Select.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export interface SelectProps
export type SelectClassKey =
| 'root'
| 'select'
| 'filled'
| 'outlined'
| 'selectMenu'
| 'disabled'
| 'icon'
| 'filled'
| 'outlined';
| 'iconFilled'
| 'iconOutlined';

declare const Select: React.ComponentType<SelectProps>;

Expand Down
8 changes: 4 additions & 4 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import warning from 'warning';
import { capitalize } from '../utils/helpers';
import { refType } from '@material-ui/utils';
import Menu from '../Menu/Menu';
import { isFilled } from '../InputBase/utils';
Expand Down Expand Up @@ -49,7 +50,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
tabIndex: tabIndexProp,
type = 'hidden',
value,
variant,
variant = 'standard',
...other
} = props;

Expand Down Expand Up @@ -261,10 +262,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
classes.root, // TODO v5: merge root and select
classes.select,
classes.selectMenu,
classes[variant],
{
[classes.disabled]: disabled,
[classes.filled]: variant === 'filled',
[classes.outlined]: variant === 'outlined',
},
className,
)}
Expand Down Expand Up @@ -299,7 +299,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
autoFocus={autoFocus}
{...other}
/>
<IconComponent className={classes.icon} />
<IconComponent className={clsx(classes.icon, classes[`icon${capitalize(variant)}`])} />
<Menu
id={`menu-${name || ''}`}
anchorEl={displayRef.current}
Expand Down

0 comments on commit f4769d0

Please sign in to comment.