Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Use custom tooltips on breadcrumb icons
Browse files Browse the repository at this point in the history
Fixes element-hq/element-web#9303

We have to track our own onHover for this, and out of safety we ensure that exactly 1 room is hovered at a time.
  • Loading branch information
turt2live committed Mar 27, 2019
1 parent 64a6b47 commit 90d7e82
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/components/views/rooms/RoomBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import MatrixClientPeg from "../../../MatrixClientPeg";
import AccessibleButton from '../elements/AccessibleButton';
import RoomAvatar from '../avatars/RoomAvatar';
import classNames from 'classnames';
import sdk from "../../../index";

const MAX_ROOMS = 20;

Expand Down Expand Up @@ -83,7 +84,24 @@ export default class RoomBreadcrumbs extends React.Component {
dis.dispatch({action: "view_room", room_id: room.roomId});
}

_onMouseEnter(room) {
this._onHover(room);
}

_onMouseLeave(room) {
this._onHover(null); // clear hover states
}

_onHover(room) {
const rooms = this.state.rooms.slice();
for (const r of rooms) {
r.hover = room && r.room.roomId === room.roomId;
}
this.setState({rooms});
}

render() {
const Tooltip = sdk.getComponent('elements.Tooltip');
// check for collapsed here and
// not at parent so we keep
// rooms in our state
Expand All @@ -92,15 +110,23 @@ export default class RoomBreadcrumbs extends React.Component {
return null;
}
const rooms = this.state.rooms;
const avatars = rooms.map(({room, animated}, i) => {
const avatars = rooms.map(({room, animated, hover}, i) => {
const isFirst = i === 0;
const classes = classNames({
"mx_RoomBreadcrumbs_preAnimate": isFirst && !animated,
"mx_RoomBreadcrumbs_animate": isFirst,
});

let tooltip = null;
if (hover) {
tooltip = <Tooltip label={room.name} />;
}

return (
<AccessibleButton className={classes} key={room.roomId} title={room.name} onClick={() => this._viewRoom(room)}>
<AccessibleButton className={classes} key={room.roomId} onClick={() => this._viewRoom(room)}
onMouseEnter={() => this._onMouseEnter(room)} onMouseLeave={() => this._onMouseLeave(room)}>
<RoomAvatar room={room} width={32} height={32} />
{tooltip}
</AccessibleButton>
);
});
Expand Down

0 comments on commit 90d7e82

Please sign in to comment.