Skip to content

Commit f4c06c0

Browse files
author
Sean Chamberlain
committed
Allows the actions of speed dial to be placed in any direction
1 parent e45ece3 commit f4c06c0

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ import { TransitionHandlerProps } from '@material-ui/core/transitions/transition
66

77
export interface SpeedDialProps
88
extends StandardProps<
9-
React.HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlerProps>,
10-
SpeedDialClassKey
11-
> {
9+
React.HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlerProps>,
10+
SpeedDialClassKey
11+
> {
12+
actionsPlacement?:
13+
| 'top'
14+
| 'bottom'
15+
| 'left'
16+
| 'right';
1217
ariaLabel: string;
1318
ButtonProps?: Partial<ButtonProps>;
1419
hidden?: boolean;

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

+36-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@ export const styles = {
1515
root: {
1616
zIndex: 1050,
1717
display: 'flex',
18-
flexDirection: 'column-reverse', // Place the Actions above the FAB.
18+
},
19+
/* Styles when actions are placed to the top */
20+
actionsTop: {
21+
flexDirection: 'column-reverse',
22+
},
23+
/* Styles when actions are placed to the bottom */
24+
actionsBottom: {
25+
flexDirection: 'column',
26+
},
27+
/* Styles when actions are placed to the left */
28+
actionsLeft: {
29+
flexDirection: 'row-reverse',
30+
},
31+
/* Styles when actions are placed to the right */
32+
actionsRight: {
33+
flexDirection: 'row',
1934
},
2035
/* Styles applied to the actions (`children` wrapper) element. */
2136
actions: {
2237
display: 'flex',
23-
flexDirection: 'column-reverse', // Display the first action at the bottom.
2438
marginBottom: 16,
2539
},
2640
/* Styles applied to the actions (`children` wrapper) element if `open={false}`. */
@@ -102,6 +116,7 @@ class SpeedDial extends React.Component {
102116
onClose,
103117
onKeyDown,
104118
open,
119+
actionsPlacement,
105120
openIcon,
106121
TransitionComponent,
107122
transitionDuration,
@@ -151,8 +166,15 @@ class SpeedDial extends React.Component {
151166
return icon;
152167
};
153168

169+
const actionsPlacementClass = {
170+
[classes.actionsTop]: actionsPlacement === 'top',
171+
[classes.actionsBottom]: actionsPlacement === 'bottom',
172+
[classes.actionsLeft]: actionsPlacement === 'left',
173+
[classes.actionsRight]: actionsPlacement === 'right',
174+
}
175+
154176
return (
155-
<div className={classNames(classes.root, classNameProp)} {...other}>
177+
<div className={classNames(classes.root, classNameProp, actionsPlacementClass)} {...other}>
156178
<TransitionComponent
157179
in={!hidden}
158180
timeout={transitionDuration}
@@ -178,7 +200,7 @@ class SpeedDial extends React.Component {
178200
</TransitionComponent>
179201
<div
180202
id={`${id}-actions`}
181-
className={classNames(classes.actions, { [classes.actionsClosed]: !open })}
203+
className={classNames(classes.actions, { [classes.actionsClosed]: !open }, actionsPlacementClass)}
182204
ref={ref => {
183205
this.actionsRef = ref;
184206
}}
@@ -191,6 +213,15 @@ class SpeedDial extends React.Component {
191213
}
192214

193215
SpeedDial.propTypes = {
216+
/**
217+
* The placement of floating actions buttons in relation to speed dial.
218+
*/
219+
actionsPlacement: PropTypes.oneOf([
220+
'top',
221+
'bottom',
222+
'left',
223+
'right',
224+
]),
194225
/**
195226
* The aria-label of the `Button` element.
196227
* Also used to provide the `id` for the `SpeedDial` element and its children.
@@ -265,6 +296,7 @@ SpeedDial.propTypes = {
265296

266297
SpeedDial.defaultProps = {
267298
hidden: false,
299+
actionsPlacement: 'top',
268300
TransitionComponent: Zoom,
269301
transitionDuration: {
270302
enter: duration.enteringScreen,

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

+22
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,26 @@ describe('<SpeedDial />', () => {
129129
assert.strictEqual(handleKeyDown.args[0][0], event);
130130
});
131131
});
132+
133+
describe('prop: actionPlacement', () => {
134+
const testPlacement = placement => {
135+
const className = `actions${placement}`;
136+
const wrapper = shallow(
137+
<SpeedDial {...defaultProps} actionsPlacement={placement.toLowerCase()} icon={icon}>
138+
<SpeedDialAction icon={icon} />
139+
<SpeedDialAction icon={icon} />
140+
</SpeedDial>,
141+
);
142+
const actionsWrapper = wrapper.childAt(1);
143+
assert.strictEqual(wrapper.hasClass(classes[className]), true);
144+
assert.strictEqual(actionsWrapper.hasClass(classes[className]), true);
145+
};
146+
147+
it('should place actions in correct position', () => {
148+
testPlacement('Left');
149+
testPlacement('Right');
150+
testPlacement('Top');
151+
testPlacement('Bottom');
152+
});
153+
});
132154
});

pages/lab/api/speed-dial.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ title: SpeedDial API
1515

1616
| Name | Type | Default | Description |
1717
|:-----|:-----|:--------|:------------|
18+
| <span class="prop-name">actionsPlacement</span> | <span class="prop-type">enum:&nbsp;'top'&nbsp;&#124;<br>&nbsp;'bottom'&nbsp;&#124;<br>&nbsp;'left'&nbsp;&#124;<br>&nbsp;'right'<br> | <span class="prop-default">'top'</span> | The placement of floating actions buttons in relation to speed dial. |
1819
| <span class="prop-name required">ariaLabel *</span> | <span class="prop-type">string |   | The aria-label of the `Button` element. Also used to provide the `id` for the `SpeedDial` element and its children. |
1920
| <span class="prop-name">ButtonProps</span> | <span class="prop-type">object |   | Properties applied to the [`Button`](/api/button) element. |
2021
| <span class="prop-name required">children *</span> | <span class="prop-type">node |   | SpeedDialActions to display when the SpeedDial is `open`. |
@@ -39,6 +40,10 @@ This property accepts the following keys:
3940
| Name | Description |
4041
|:-----|:------------|
4142
| <span class="prop-name">root</span> | Styles applied to the root element.
43+
| <span class="prop-name">actionsTop</span> | Styles when actions are placed to the top
44+
| <span class="prop-name">actionsBottom</span> | Styles when actions are placed to the bottom
45+
| <span class="prop-name">actionsLeft</span> | Styles when actions are placed to the left
46+
| <span class="prop-name">actionsRight</span> | Styles when actions are placed to the right
4247
| <span class="prop-name">actions</span> | Styles applied to the actions (`children` wrapper) element.
4348
| <span class="prop-name">actionsClosed</span> | Styles applied to the actions (`children` wrapper) element if `open={false}`.
4449

0 commit comments

Comments
 (0)