Skip to content

Commit 765fdae

Browse files
committed
[SpeedDial] Fix react warnings
onKeyDown was applied to the button and the SpeedDialAction. However the Action did not process onKeyDown and passing the same event listener to different components is ambiguous.
1 parent 262a6f6 commit 765fdae

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/material-ui-lab/src/SpeedDial/SpeedDial.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,15 @@ class SpeedDial extends React.Component {
158158
return React.cloneElement(child, {
159159
delay,
160160
open,
161-
onKeyDown: this.handleKeyDown,
162161
id: `${id}-item-${validChildCount}`,
163162
});
164163
});
165164

166165
const icon = () => {
167-
if (!React.isValidElement(iconProp)) {
168-
return iconProp;
169-
}
170-
if (isMuiElement(iconProp, ['SpeedDialIcon'])) {
166+
if (React.isValidElement(iconProp) && isMuiElement(iconProp, ['SpeedDialIcon'])) {
171167
return React.cloneElement(iconProp, { open });
172168
}
173-
return icon;
169+
return iconProp;
174170
};
175171

176172
const actionsPlacementClass = {

packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react';
22
import { assert } from 'chai';
33
import { spy } from 'sinon';
4-
import { createShallow, getClasses } from '@material-ui/core/test-utils';
4+
import { createMount, createShallow, getClasses } from '@material-ui/core/test-utils';
55
import Icon from '@material-ui/core/Icon';
66
import Button from '@material-ui/core/Button';
77
import SpeedDial from './SpeedDial';
88
import SpeedDialAction from '../SpeedDialAction';
99

1010
describe('<SpeedDial />', () => {
11+
let mount;
1112
let shallow;
1213
let classes;
1314
const icon = <Icon>font_icon</Icon>;
@@ -17,6 +18,7 @@ describe('<SpeedDial />', () => {
1718
};
1819

1920
before(() => {
21+
mount = createMount();
2022
shallow = createShallow({ dive: true });
2123
classes = getClasses(
2224
<SpeedDial {...defaultProps} icon={icon}>
@@ -25,6 +27,16 @@ describe('<SpeedDial />', () => {
2527
);
2628
});
2729

30+
it('should render with a minimal setup', () => {
31+
const wrapper = mount(
32+
<SpeedDial {...defaultProps} icon={icon}>
33+
<SpeedDialAction icon={<Icon>save_icon</Icon>} tooltipTitle="Save" />
34+
</SpeedDial>,
35+
);
36+
37+
wrapper.unmount();
38+
});
39+
2840
it('should render a Fade transition', () => {
2941
const wrapper = shallow(
3042
<SpeedDial {...defaultProps} icon={icon}>

0 commit comments

Comments
 (0)