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

feat(tabs): close tab on middle mouse btn #836

Merged
merged 1 commit into from
Jan 17, 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
9 changes: 6 additions & 3 deletions src/renderer/root/components/AuthenticatedLayout/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default class Tab extends React.PureComponent {
icon: string,
loading: bool,
onClick: func,
onClose: func
onClose: func,
onMouseUp: func
};

static defaultProps = {
Expand All @@ -27,7 +28,8 @@ export default class Tab extends React.PureComponent {
icon: null,
loading: false,
onClick: noop,
onClose: noop
onClose: noop,
onMouseUp: noop
};

state = {
Expand All @@ -45,7 +47,7 @@ export default class Tab extends React.PureComponent {
}

render() {
const { className, active, title, onClick } = this.props;
const { className, active, title, onClick, onMouseUp } = this.props;
const { width, show } = this.state;

return (
Expand All @@ -55,6 +57,7 @@ export default class Tab extends React.PureComponent {
role="button"
tabIndex={0}
onClick={onClick}
onMouseUp={onMouseUp}
>
{this.renderIcon()}
<span className={styles.title}>{title}</span>
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/root/components/AuthenticatedLayout/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ export default class Tabs extends React.PureComponent {
active={sessionId === this.props.activeSessionId}
onClick={this.handleClick(sessionId)}
onClose={this.handleClose(sessionId)}
onMouseUp={(e) => this.handleMouseUp(sessionId, e)}
/>
);
};

handleMouseUp = (sessionId, event) => {
// Handle close tab using middle mouse click
if (event.button === 1) {
this.props.onClose(sessionId);
}
};

handleClick = (sessionId) => {
return () => {
this.props.setActiveTab(sessionId);
Expand Down