mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
InfoTooltip: refactor component to be accessible (#43613)
* InfoTooltip: refactor component to be accessible * new: create ghostMode prop to allow turning on/off button styles * update infoToolTip component to use ghostMode prop * update story to show ghostMode state * fix condition to work properly * nit fix * revert changes to former infoTooltip state * InfoTooltip: use iconButton instead to achieve keyboard a11y * fix minor type nit
This commit is contained in:
parent
8dc4c23a89
commit
62d44fcffc
@ -5,7 +5,7 @@ import { stylesFactory } from '../../themes/stylesFactory';
|
||||
import { css, cx } from '@emotion/css';
|
||||
import { useTheme2 } from '../../themes/ThemeContext';
|
||||
import { GrafanaTheme2, colorManipulator } from '@grafana/data';
|
||||
import { Tooltip } from '../Tooltip/Tooltip';
|
||||
import { PopoverContent, Tooltip } from '../Tooltip/Tooltip';
|
||||
import { TooltipPlacement } from '../Tooltip/PopoverController';
|
||||
import { getFocusStyles, getMouseFocusStyles } from '../../themes/mixins';
|
||||
|
||||
@ -21,7 +21,7 @@ export interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
/** Type od the icon - mono or default */
|
||||
iconType?: IconType;
|
||||
/** Tooltip content to display on hover */
|
||||
tooltip?: string;
|
||||
tooltip?: PopoverContent;
|
||||
/** Position of the tooltip */
|
||||
tooltipPlacement?: TooltipPlacement;
|
||||
/** Variant to change the color of the Icon */
|
||||
@ -49,9 +49,10 @@ export const IconButton = React.forwardRef<HTMLButtonElement, Props>(
|
||||
) => {
|
||||
const theme = useTheme2();
|
||||
const styles = getStyles(theme, size, variant);
|
||||
const tooltipString = typeof tooltip === 'string' ? tooltip : '';
|
||||
|
||||
const button = (
|
||||
<button ref={ref} aria-label={ariaLabel || tooltip || ''} {...restProps} className={cx(styles.button, className)}>
|
||||
<button ref={ref} aria-label={ariaLabel || tooltipString} {...restProps} className={cx(styles.button, className)}>
|
||||
<Icon name={name} size={size} className={styles.icon} type={iconType} />
|
||||
</button>
|
||||
);
|
||||
|
@ -1,15 +1,11 @@
|
||||
import React from 'react';
|
||||
import { Tooltip, TooltipProps, PopoverContent } from '../Tooltip/Tooltip';
|
||||
import { Icon } from '../Icon/Icon';
|
||||
import { PopoverContent, TooltipProps } from '../Tooltip/Tooltip';
|
||||
import { IconButton } from '../IconButton/IconButton';
|
||||
|
||||
interface InfoTooltipProps extends Omit<TooltipProps, 'children' | 'content'> {
|
||||
children: PopoverContent;
|
||||
}
|
||||
|
||||
export const InfoTooltip = ({ children, ...restProps }: InfoTooltipProps) => {
|
||||
return (
|
||||
<Tooltip content={children} {...restProps}>
|
||||
<Icon name="info-circle" />
|
||||
</Tooltip>
|
||||
);
|
||||
return <IconButton name="info-circle" tooltip={children} {...restProps} />;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user