diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 479f297e1a1..84e5d786552 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -742,11 +742,6 @@ "count": 1 } }, - "packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx": { - "no-restricted-syntax": { - "count": 1 - } - }, "packages/grafana-ui/src/components/PanelChrome/PanelContext.ts": { "@typescript-eslint/no-explicit-any": { "count": 2 diff --git a/packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx b/packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx index d7a85381e9e..7e993ac8a25 100644 --- a/packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx +++ b/packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx @@ -1,9 +1,7 @@ import { action } from '@storybook/addon-actions'; import { Meta } from '@storybook/react'; -import { StoryExample } from '../../utils/storybook/StoryExample'; import { IconButton } from '../IconButton/IconButton'; -import { Stack } from '../Layout/Stack/Stack'; import { ToolbarButton } from '../ToolbarButton/ToolbarButton'; import { PageToolbar } from './PageToolbar'; @@ -11,48 +9,46 @@ import { PageToolbar } from './PageToolbar'; const meta: Meta = { title: 'Navigation/Deprecated/PageToolbar', component: PageToolbar, - parameters: { - // TODO fix a11y issue in story and remove this - a11y: { test: 'off' }, - }, }; -export const Examples = () => { +export const WithNonClickableTitle = () => { return ( - - - - - Sync - - - - , - , - ]} - > - - - Sync - Settings - - - - action('Go back')}> - - - Discard - Apply - - - + + + Sync + + ); +}; + +export const WithClickableTitleAndParent = () => { + return ( + , + , + ]} + > + + + Sync + Settings + + ); +}; + +export const GoBackVersion = () => { + return ( + action('Go back')}> + + + Discard + Apply + ); }; diff --git a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.story.tsx b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.story.tsx index 23c3426f69d..71ba96ba583 100644 --- a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.story.tsx +++ b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.story.tsx @@ -76,6 +76,7 @@ export const BasicWithIcon: StoryFn = (args) => { icon={args.icon} isOpen={args.isOpen} tooltip={args.tooltip} + aria-label="This is an aria-label" disabled={args.disabled} fullWidth={args.fullWidth} isHighlighted={args.isHighlighted} diff --git a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx index 40b468d73fb..c1f99b0db93 100644 --- a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx +++ b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx @@ -1,5 +1,5 @@ import { cx, css } from '@emotion/css'; -import { forwardRef, ButtonHTMLAttributes } from 'react'; +import { forwardRef, ButtonHTMLAttributes, ReactNode } from 'react'; import * as React from 'react'; import { GrafanaTheme2, IconName, isIconName } from '@grafana/data'; @@ -12,7 +12,7 @@ import { getActiveButtonStyles, getPropertiesForVariant } from '../Button/Button import { Icon } from '../Icon/Icon'; import { Tooltip } from '../Tooltip/Tooltip'; -type CommonProps = { +interface BaseProps extends ButtonHTMLAttributes { /** Icon name */ icon?: IconName | React.ReactNode; /** Icon size */ @@ -35,9 +35,21 @@ type CommonProps = { iconOnly?: boolean; /** Show highlight dot */ isHighlighted?: boolean; -}; +} -export type ToolbarButtonProps = CommonProps & ButtonHTMLAttributes; +interface BasePropsWithChildren extends BaseProps { + children: ReactNode; +} + +interface BasePropsWithTooltip extends BaseProps { + tooltip: string; +} + +interface BasePropsWithAriaLabel extends BaseProps { + ['aria-label']: string; +} + +export type ToolbarButtonProps = BasePropsWithChildren | BasePropsWithTooltip | BasePropsWithAriaLabel; export type ToolbarButtonVariant = 'default' | 'primary' | 'destructive' | 'active' | 'canvas'; @@ -46,72 +58,68 @@ export type ToolbarButtonVariant = 'default' | 'primary' | 'destructive' | 'acti * * https://developers.grafana.com/ui/latest/index.html?path=/docs/navigation-toolbarbutton--docs */ -export const ToolbarButton = forwardRef( - ( +export const ToolbarButton = forwardRef((props, ref) => { + const styles = useStyles2(getStyles); + const { + tooltip, + icon, + iconSize, + className, + children, + imgSrc, + imgAlt, + fullWidth, + isOpen, + narrow, + variant = 'default', + iconOnly, + 'aria-label': ariaLabel, + isHighlighted, + ...rest + } = props; + + const buttonStyles = cx( { - tooltip, - icon, - iconSize, - className, - children, - imgSrc, - imgAlt, - fullWidth, - isOpen, - narrow, - variant = 'default', - iconOnly, - 'aria-label': ariaLabel, - isHighlighted, - ...rest + [styles.button]: true, + [styles.buttonFullWidth]: fullWidth, + [styles.narrow]: narrow, }, - ref - ) => { - const styles = useStyles2(getStyles); + styles[variant], + className + ); - const buttonStyles = cx( - { - [styles.button]: true, - [styles.buttonFullWidth]: fullWidth, - [styles.narrow]: narrow, - }, - styles[variant], - className - ); + const contentStyles = cx({ + [styles.content]: true, + [styles.contentWithIcon]: !!icon, + [styles.contentWithRightIcon]: isOpen !== undefined, + }); - const contentStyles = cx({ - [styles.content]: true, - [styles.contentWithIcon]: !!icon, - [styles.contentWithRightIcon]: isOpen !== undefined, - }); + const body = ( + + ); - const body = ( - - ); - - return tooltip ? ( - - {body} - - ) : ( - body - ); - } -); + return tooltip ? ( + + {body} + + ) : ( + body + ); +}); ToolbarButton.displayName = 'ToolbarButton'; diff --git a/public/app/features/explore/LiveTailButton.tsx b/public/app/features/explore/LiveTailButton.tsx index d594e3618bc..e9a31fbb8d8 100644 --- a/public/app/features/explore/LiveTailButton.tsx +++ b/public/app/features/explore/LiveTailButton.tsx @@ -2,8 +2,8 @@ import { css } from '@emotion/css'; import { useRef } from 'react'; import { CSSTransition } from 'react-transition-group'; -import { Trans, t } from '@grafana/i18n'; -import { Tooltip, ButtonGroup, ToolbarButton } from '@grafana/ui'; +import { t } from '@grafana/i18n'; +import { ButtonGroup, ToolbarButton } from '@grafana/ui'; type LiveTailButtonProps = { splitted: boolean; @@ -24,31 +24,21 @@ export function LiveTailButton(props: LiveTailButtonProps) { return ( - - Pause the live stream - - ) : ( - <> - Start live stream your logs - - ) + - - {isLive && isPaused - ? t('explore.live-tail-button.paused', 'Paused') - : t('explore.live-tail-button.live', 'Live')} - - + {isLive && isPaused + ? t('explore.live-tail-button.paused', 'Paused') + : t('explore.live-tail-button.live', 'Live')} + - - - Stop and exit the live stream - - - } - placement="bottom" - > - - + ); diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx index 74d25ed8c1f..b6e556481a9 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx @@ -72,14 +72,14 @@ describe('', () => { it('renders without exploding', () => { render(); expect(screen.getByTestId('ListView')).toBeInTheDocument(); - expect(screen.getByTitle('Scroll to top')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Scroll to top' })).toBeInTheDocument(); }); it('renders when a trace is not set', () => { props = { ...props, trace: null as unknown as Trace }; render(); expect(screen.getByTestId('ListView')).toBeInTheDocument(); - expect(screen.getByTitle('Scroll to top')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Scroll to top' })).toBeInTheDocument(); }); it('renders ListView', () => { diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.tsx index 58efda7659f..d53cdf4a94e 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.tsx @@ -644,7 +644,7 @@ export class UnthemedVirtualizedTraceView extends React.Component )} diff --git a/public/app/features/stars/StarToolbarButton.tsx b/public/app/features/stars/StarToolbarButton.tsx index 7a4b61afa0a..b6af50ce36c 100644 --- a/public/app/features/stars/StarToolbarButton.tsx +++ b/public/app/features/stars/StarToolbarButton.tsx @@ -50,12 +50,9 @@ export function StarToolbarButton({ title, group, kind, id, onStarChange }: Prop })(); const tooltipAndLabel = (() => { - if (isLoading) { - return {}; - } return isStarred - ? { tooltip: tooltips.unstar, label: tooltips.unstarWithTitle } - : { tooltip: tooltips.star, label: tooltips.starWithTitle }; + ? { tooltip: tooltips.unstar, label: isLoading ? undefined : tooltips.unstarWithTitle } + : { tooltip: tooltips.star, label: isLoading ? undefined : tooltips.starWithTitle }; })(); const icon = ;