Make tooltips keyboard accessible (#7281)
* show tooltips on hover in eventtile Signed-off-by: Kerry Archibald <kerrya@element.io> * use tooltip props pass thru * use tooltiptarget in InfoTooltip Signed-off-by: Kerry Archibald <kerrya@element.io> * use target in TestWithTooltip Signed-off-by: Kerry Archibald <kerrya@element.io> * tsc fixes Signed-off-by: Kerry Archibald <kerrya@element.io> * test tooltip target Signed-off-by: Kerry Archibald <kerrya@element.io> * lint fix Signed-off-by: Kerry Archibald <kerrya@element.io> * rename tooltip handlers Signed-off-by: Kerry Archibald <kerrya@element.io> * update copyright to 2021 Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
4712ae49b2
commit
0c850b2f13
11 changed files with 242 additions and 98 deletions
|
@ -17,48 +17,28 @@ limitations under the License.
|
|||
|
||||
import React from 'react';
|
||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||
import Tooltip from './Tooltip';
|
||||
import { TooltipTarget } from './TooltipTarget';
|
||||
|
||||
interface IProps {
|
||||
helpText: React.ReactNode | string;
|
||||
}
|
||||
|
||||
interface IState {
|
||||
hover: boolean;
|
||||
}
|
||||
|
||||
@replaceableComponent("views.elements.TooltipButton")
|
||||
export default class TooltipButton extends React.Component<IProps, IState> {
|
||||
export default class TooltipButton extends React.Component<IProps> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
hover: false,
|
||||
};
|
||||
}
|
||||
|
||||
private onMouseOver = () => {
|
||||
this.setState({
|
||||
hover: true,
|
||||
});
|
||||
};
|
||||
|
||||
private onMouseLeave = () => {
|
||||
this.setState({
|
||||
hover: false,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const tip = this.state.hover ? <Tooltip
|
||||
className="mx_TooltipButton_container"
|
||||
tooltipClassName="mx_TooltipButton_helpText"
|
||||
label={this.props.helpText}
|
||||
/> : <div />;
|
||||
return (
|
||||
<div className="mx_TooltipButton" onMouseOver={this.onMouseOver} onMouseLeave={this.onMouseLeave}>
|
||||
<TooltipTarget
|
||||
className="mx_TooltipButton_container"
|
||||
tooltipClassName="mx_TooltipButton_helpText"
|
||||
tooltipTargetClassName="mx_TooltipButton"
|
||||
label={this.props.helpText}
|
||||
>
|
||||
?
|
||||
{ tip }
|
||||
</div>
|
||||
</TooltipTarget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue