Skip to content

Commit

Permalink
Accessibility: Improved keyboard accessibility in BigValue (#59830)
Browse files Browse the repository at this point in the history
use appropriate elements when rendering BigValue

(cherry picked from commit c75ed8f)
  • Loading branch information
lpskdl authored and grafanabot committed Dec 14, 2022
1 parent b297cbf commit ec5218f
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/grafana-ui/src/components/BigValue/BigValue.tsx
@@ -1,9 +1,11 @@
import { cx } from '@emotion/css';
import React, { PureComponent } from 'react';

import { DisplayValue, DisplayValueAlignmentFactors, FieldSparkline, VizOrientation } from '@grafana/data';
import { VizTextDisplayOptions } from '@grafana/schema';

import { Themeable2 } from '../../types';
import { clearButtonStyles } from '../Button';
import { FormattedValueDisplay } from '../FormattedValueDisplay/FormattedValueDisplay';

import { buildLayout } from './BigValueLayout';
Expand Down Expand Up @@ -79,7 +81,7 @@ export class BigValue extends PureComponent<Props> {
};

render() {
const { onClick, className, hasLinks } = this.props;
const { onClick, className, hasLinks, theme } = this.props;
const layout = buildLayout(this.props);
const panelStyles = layout.getPanelStyles();
const valueAndTitleContainerStyles = layout.getValueAndTitleContainerStyles();
Expand All @@ -90,14 +92,32 @@ export class BigValue extends PureComponent<Props> {
// When there is an outer data link this tooltip will override the outer native tooltip
const tooltip = hasLinks ? undefined : textValues.tooltip;

if (!onClick) {
return (
<div className={className} style={panelStyles} title={tooltip}>
<div style={valueAndTitleContainerStyles}>
{textValues.title && <div style={titleStyles}>{textValues.title}</div>}
<FormattedValueDisplay value={textValues} style={valueStyles} />
</div>
{layout.renderChart()}
</div>
);
}

return (
<div className={className} style={panelStyles} onClick={onClick} title={tooltip}>
<button
type="button"
className={cx(clearButtonStyles(theme), className)}
style={panelStyles}
onClick={onClick}
title={tooltip}
>
<div style={valueAndTitleContainerStyles}>
{textValues.title && <div style={titleStyles}>{textValues.title}</div>}
<FormattedValueDisplay value={textValues} style={valueStyles} />
</div>
{layout.renderChart()}
</div>
</button>
);
}
}

0 comments on commit ec5218f

Please sign in to comment.