Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Select] Fix display when no value is selected #16294

Merged
merged 4 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/material-ui-styles/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ponyfillGlobal } from '@material-ui/utils';

/* Warning if there are several instances of @material-ui/styles */
if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
if (
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
typeof window !== 'undefined'
) {
ponyfillGlobal['__@material-ui/styles-init__'] =
ponyfillGlobal['__@material-ui/styles-init__'] || 0;

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ListItem/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : Reac
const ListItem = React.forwardRef(function ListItem(props, ref) {
const {
alignItems = 'center',
autoFocus,
autoFocus = false,
button = false,
children: childrenProp,
classes,
Expand Down
9 changes: 8 additions & 1 deletion packages/material-ui/src/MenuList/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ function moveFocus(list, currentFocus, disableListWrap, traversalFunction, textC
const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;

const MenuList = React.forwardRef(function MenuList(props, ref) {
const { actions, autoFocus, className, onKeyDown, disableListWrap = false, ...other } = props;
const {
actions,
autoFocus = false,
className,
onKeyDown,
disableListWrap = false,
...other
} = props;
const listRef = React.useRef(null);
const textCriteriaRef = React.useRef({
keys: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
delete other['aria-invalid'];

let display;
let displaySingle = '';
let displaySingle;
const displayMultiple = [];
let computeDisplay = false;

Expand Down
8 changes: 4 additions & 4 deletions packages/material-ui/src/Select/SelectInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('<SelectInput />', () => {
<SelectInput {...defaultProps} SelectDisplayProps={{ 'data-test': 'SelectDisplay' }} />,
);

const selectDisplay = wrapper.find('[data-mui-test="SelectDisplay"]');
const selectDisplay = wrapper.find('[role="button"]');
assert.strictEqual(selectDisplay.props()['data-test'], 'SelectDisplay');
});
});
Expand Down Expand Up @@ -287,15 +287,15 @@ describe('<SelectInput />', () => {
describe('prop: autoWidth', () => {
it('should take the anchor width into account', () => {
const wrapper = mount(<SelectInput {...defaultProps} />);
const selectDisplay = wrapper.find('[data-mui-test="SelectDisplay"]').instance();
const selectDisplay = wrapper.find('[role="button"]').instance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

stub(selectDisplay, 'clientWidth').get(() => 14);
wrapper.find(`.${defaultProps.classes.select}`).simulate('click');
assert.strictEqual(wrapper.find(Menu).props().PaperProps.style.minWidth, 14);
});

it('should not take the anchor width into account', () => {
const wrapper = mount(<SelectInput {...defaultProps} autoWidth />);
const selectDisplay = wrapper.find('[data-mui-test="SelectDisplay"]').instance();
const selectDisplay = wrapper.find('[role="button"]').instance();
stub(selectDisplay, 'clientWidth').get(() => 14);
wrapper.find(`.${defaultProps.classes.select}`).simulate('click');
assert.strictEqual(wrapper.find(Menu).props().PaperProps.style.minWidth, null);
Expand All @@ -305,7 +305,7 @@ describe('<SelectInput />', () => {
describe('prop: multiple', () => {
it('should take precedence', () => {
const wrapper = shallow(<SelectInput {...defaultProps} disabled tabIndex={0} />);
assert.strictEqual(wrapper.find('[data-mui-test="SelectDisplay"]').props().tabIndex, 0);
assert.strictEqual(wrapper.find('[role="button"]').props().tabIndex, 0);
});

it('should serialize multiple select value', () => {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/list-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Uses an additional container component if `ListItemSecondaryAction` is the last
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">alignItems</span> | <span class="prop-type">enum:&nbsp;'flex-start'&nbsp;&#124;<br>&nbsp;'center'<br></span> | <span class="prop-default">'center'</span> | Defines the `align-items` style property. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | | If `true`, the list item will be focused during the first mount. Focus will also be triggered if the value changes from false to true. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the list item will be focused during the first mount. Focus will also be triggered if the value changes from false to true. |
| <span class="prop-name">button</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the list item will be a button (using `ButtonBase`). |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. If a `ListItemSecondaryAction` is used it must be the last child. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
Expand Down
2 changes: 1 addition & 1 deletion pages/api/menu-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import MenuList from '@material-ui/core/MenuList';

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | | If `true`, the list will be focused during the first mount. Focus will also be triggered if the value changes from false to true. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the list will be focused during the first mount. Focus will also be triggered if the value changes from false to true. |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | MenuList contents, normally `MenuItem`s. |
| <span class="prop-name">disableListWrap</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the menu items will not wrap focus. |

Expand Down
4 changes: 1 addition & 3 deletions test/regressions/tests/Select/SelectAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FormHelperText from '@material-ui/core/FormHelperText';
import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';

function SelectAlignment() {
export default function SelectAlignment() {
return (
<div>
<FormControl>
Expand Down Expand Up @@ -35,5 +35,3 @@ function SelectAlignment() {
</div>
);
}

export default SelectAlignment;
11 changes: 11 additions & 0 deletions test/regressions/tests/Select/SelectMissingValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';

export default function SelectMissingValue() {
return (
<Select value={0}>
<MenuItem value={10}>Ten</MenuItem>
</Select>
);
}
4 changes: 1 addition & 3 deletions test/regressions/tests/Select/SelectOverflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';

function SelectOverflow() {
export default function SelectOverflow() {
return (
<Select value={10} style={{ maxWidth: 100 }}>
<MenuItem value="">
Expand All @@ -12,5 +12,3 @@ function SelectOverflow() {
</Select>
);
}

export default SelectOverflow;