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

[SpeedDial] Allow a tooltip placement prop #12244

Merged
merged 2 commits into from
Aug 7, 2018
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
1 change: 1 addition & 0 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface SpeedDialProps
> {
ariaLabel: string;
ButtonProps?: Partial<ButtonProps>;
direction?: 'up' | 'down' | 'left' | 'right';
hidden?: boolean;
icon: React.ReactNode;
onClose?: React.ReactEventHandler<{}>;
Expand Down
39 changes: 35 additions & 4 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ export const styles = {
root: {
zIndex: 1050,
display: 'flex',
flexDirection: 'column-reverse', // Place the Actions above the FAB.
pointerEvents: 'none',
},
/* Styles applied to the Button component. */
fab: {
pointerEvents: 'auto',
},
/* Styles applied to the root and action container elements when direction="up" */
directionUp: {
flexDirection: 'column-reverse',
},
/* Styles applied to the root and action container elements when direction="down" */
directionDown: {
flexDirection: 'column',
},
/* Styles applied to the root and action container elements when direction="left" */
directionLeft: {
flexDirection: 'row-reverse',
},
/* Styles applied to the root and action container elements when direction="right" */
directionRight: {
flexDirection: 'row',
},
/* Styles applied to the actions (`children` wrapper) element. */
actions: {
display: 'flex',
flexDirection: 'column-reverse', // Display the first action at the bottom.
paddingBottom: 16,
pointerEvents: 'auto',
},
Expand Down Expand Up @@ -109,6 +123,7 @@ class SpeedDial extends React.Component {
onClose,
onKeyDown,
open,
direction,
openIcon,
TransitionComponent,
transitionDuration,
Expand Down Expand Up @@ -158,8 +173,15 @@ class SpeedDial extends React.Component {
return icon;
};

const actionsPlacementClass = {
[classes.directionUp]: direction === 'up',
[classes.directionDown]: direction === 'down',
[classes.directionLeft]: direction === 'left',
[classes.directionRight]: direction === 'right',
};

return (
<div className={classNames(classes.root, classNameProp)} {...other}>
<div className={classNames(classes.root, actionsPlacementClass, classNameProp)} {...other}>
<TransitionComponent
in={!hidden}
timeout={transitionDuration}
Expand All @@ -186,7 +208,11 @@ class SpeedDial extends React.Component {
</TransitionComponent>
<div
id={`${id}-actions`}
className={classNames(classes.actions, { [classes.actionsClosed]: !open })}
className={classNames(
classes.actions,
{ [classes.actionsClosed]: !open },
actionsPlacementClass,
)}
ref={ref => {
this.actionsRef = ref;
}}
Expand Down Expand Up @@ -221,6 +247,10 @@ SpeedDial.propTypes = {
* @ignore
*/
className: PropTypes.string,
/**
* The direction the actions open relative to the floating action button.
*/
direction: PropTypes.oneOf(['up', 'down', 'left', 'right']),
/**
* If `true`, the SpeedDial will be hidden.
*/
Expand Down Expand Up @@ -273,6 +303,7 @@ SpeedDial.propTypes = {

SpeedDial.defaultProps = {
hidden: false,
direction: 'top',
TransitionComponent: Zoom,
transitionDuration: {
enter: duration.enteringScreen,
Expand Down
22 changes: 22 additions & 0 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,26 @@ describe('<SpeedDial />', () => {
assert.strictEqual(handleKeyDown.args[0][0], event);
});
});

describe('prop: direction', () => {
const testDirection = direction => {
const className = `direction${direction}`;
const wrapper = shallow(
<SpeedDial {...defaultProps} direction={direction.toLowerCase()} icon={icon}>
<SpeedDialAction icon={icon} />
<SpeedDialAction icon={icon} />
</SpeedDial>,
);
const actionsWrapper = wrapper.childAt(1);
assert.strictEqual(wrapper.hasClass(classes[className]), true);
assert.strictEqual(actionsWrapper.hasClass(classes[className]), true);
};

it('should place actions in correct position', () => {
testDirection('Up');
testDirection('Down');
testDirection('Left');
testDirection('Right');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface SpeedDialActionProps
ButtonProps?: Partial<ButtonProps>;
delay?: number;
icon: React.ReactNode;
tooltipPlacement?: string;
tooltipTitle?: React.ReactNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SpeedDialAction extends React.Component {
onClick,
open,
tooltipTitle,
tooltipPlacement,
...other
} = this.props;

Expand All @@ -63,7 +64,7 @@ class SpeedDialAction extends React.Component {
id={id}
className={classNames(classes.root, classNameProp)}
title={tooltipTitle}
placement="left"
placement={tooltipPlacement}
onClose={this.handleTooltipClose}
onOpen={this.handleTooltipOpen}
open={open && this.state.tooltipOpen}
Expand Down Expand Up @@ -124,6 +125,10 @@ SpeedDialAction.propTypes = {
* @ignore
*/
open: PropTypes.bool,
/**
* Placement of the tooltip.
*/
tooltipPlacement: PropTypes.string,
/**
* Label to display in the tooltip.
*/
Expand All @@ -133,6 +138,7 @@ SpeedDialAction.propTypes = {
SpeedDialAction.defaultProps = {
delay: 0,
open: false,
tooltipPlacement: 'left',
};

export default withStyles(styles, { name: 'MuiSpeedDialAction' })(SpeedDialAction);
1 change: 1 addition & 0 deletions pages/lab/api/speed-dial-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ title: SpeedDialAction API
| <span class="prop-name">classes</span> | <span class="prop-type">object |   | Useful to extend the style applied to components. |
| <span class="prop-name">delay</span> | <span class="prop-type">number | <span class="prop-default">0</span> | Adds a transition delay, to allow a series of SpeedDialActions to be animated. |
| <span class="prop-name required">icon *</span> | <span class="prop-type">node |   | The Icon to display in the SpeedDial Floating Action Button. |
| <span class="prop-name">tooltipPlacement</span> | <span class="prop-type">string | <span class="prop-default">'left'</span> | Placement of the tooltip. |
| <span class="prop-name">tooltipTitle</span> | <span class="prop-type">node |   | Label to display in the tooltip. |

Any other properties supplied will be spread to the root element (native element).
Expand Down
5 changes: 5 additions & 0 deletions pages/lab/api/speed-dial.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ title: SpeedDial API
| <span class="prop-name">ButtonProps</span> | <span class="prop-type">object |   | Properties applied to the [`Button`](/api/button) element. |
| <span class="prop-name required">children *</span> | <span class="prop-type">node |   | SpeedDialActions to display when the SpeedDial is `open`. |
| <span class="prop-name">classes</span> | <span class="prop-type">object |   | Override or extend the styles applied to the component. See [CSS API](#css-api) below for more details. |
| <span class="prop-name">direction</span> | <span class="prop-type">enum:&nbsp;'up'&nbsp;&#124;<br>&nbsp;'down'&nbsp;&#124;<br>&nbsp;'left'&nbsp;&#124;<br>&nbsp;'right'<br> | <span class="prop-default">'top'</span> | The direction the actions open relative to the floating action button. |
| <span class="prop-name">hidden</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, the SpeedDial will be hidden. |
| <span class="prop-name required">icon *</span> | <span class="prop-type">element |   | The icon to display in the SpeedDial Floating Action Button. The `SpeedDialIcon` component provides a default Icon with animation. |
| <span class="prop-name">onClose</span> | <span class="prop-type">func |   | Callback fired when the component requests to be closed.<br><br>**Signature:**<br>`function(event: object, key: string) => void`<br>*event:* The event source of the callback<br>*key:* The key pressed |
Expand All @@ -40,6 +41,10 @@ This property accepts the following keys:
|:-----|:------------|
| <span class="prop-name">root</span> | Styles applied to the root element.
| <span class="prop-name">fab</span> | Styles applied to the Button component.
| <span class="prop-name">directionUp</span> | Styles applied to the root and action container elements when direction="up"
| <span class="prop-name">directionDown</span> | Styles applied to the root and action container elements when direction="down"
| <span class="prop-name">directionLeft</span> | Styles applied to the root and action container elements when direction="left"
| <span class="prop-name">directionRight</span> | Styles applied to the root and action container elements when direction="right"
| <span class="prop-name">actions</span> | Styles applied to the actions (`children` wrapper) element.
| <span class="prop-name">actionsClosed</span> | Styles applied to the actions (`children` wrapper) element if `open={false}`.

Expand Down