Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] (Accessibility) add aria-label to chart type icon #84493

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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