Skip to content

Commit

Permalink
[Lens] (Accessibility) add aria-label to chart type icon (#84493)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra authored Nov 30, 2020
1 parent de5edaa commit f23d2e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ export function LayerSettings({
return null;
}

const a11yText = i18n.translate('xpack.lens.editLayerSettings', {
defaultMessage: 'Edit layer settings',
});
const a11yText = (chartType?: string) => {
if (chartType) {
return i18n.translate('xpack.lens.editLayerSettingsChartType', {
defaultMessage: 'Edit layer settings, {chartType}',
values: {
chartType,
},
});
}
return i18n.translate('xpack.lens.editLayerSettings', {
defaultMessage: 'Edit layer settings',
});
};

const contextMenuIcon = activeVisualization.getLayerContextMenuIcon?.(layerConfigProps);
return (
<EuiPopover
id={`lnsLayerPopover_${layerId}`}
Expand All @@ -43,9 +54,9 @@ export function LayerSettings({
>
<ToolbarButton
size="s"
iconType={activeVisualization.getLayerContextMenuIcon?.(layerConfigProps) || 'gear'}
aria-label={a11yText}
title={a11yText}
iconType={contextMenuIcon?.icon || 'gear'}
aria-label={a11yText(contextMenuIcon?.label || '')}
title={a11yText(contextMenuIcon?.label || '')}
onClick={() => setIsOpen(!isOpen)}
data-test-subj="lns_layer_settings"
/>
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ export interface Visualization<T = unknown> {
* Visualizations can provide a custom icon which will open a layer-specific popover
* If no icon is provided, gear icon is default
*/
getLayerContextMenuIcon?: (opts: { state: T; layerId: string }) => IconType | undefined;
getLayerContextMenuIcon?: (opts: {
state: T;
layerId: string;
}) => { icon: IconType | 'gear'; label: string } | undefined;

/**
* The frame is telling the visualization to update or set a dimension based on user interaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ export const getXyVisualization = ({

getLayerContextMenuIcon({ state, layerId }) {
const layer = state.layers.find((l) => l.layerId === layerId);
return visualizationTypes.find((t) => t.id === layer?.seriesType)?.icon;
const visualizationType = visualizationTypes.find((t) => t.id === layer?.seriesType);
return {
icon: visualizationType?.icon || 'gear',
label: visualizationType?.label || '',
};
},

renderLayerContextMenu(domElement, props) {
Expand Down

0 comments on commit f23d2e6

Please sign in to comment.