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

a11y: add labels for editor toolbar #9210

Merged
merged 2 commits into from
May 26, 2022
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 @@ -111,6 +111,7 @@ export const FieldToolbar = React.memo((props: FieldToolbarProps) => {
commandBarButtonAs: () => (
<TooltipTemplateButton
key="template"
ariaLabel={formatMessage('Insert a template reference')}
disabled={!templateRefPayload?.data?.templates?.length}
dismissHandlerClassName={dismissHandlerClassName}
payload={templateRefPayload}
Expand All @@ -123,6 +124,7 @@ export const FieldToolbar = React.memo((props: FieldToolbarProps) => {
commandBarButtonAs: () => (
<TooltipPropertyButton
key="property"
ariaLabel={formatMessage('Insert a property reference in memory')}
disabled={!propertyRefPayload?.data?.properties?.length}
dismissHandlerClassName={dismissHandlerClassName}
payload={propertyRefPayload}
Expand All @@ -134,6 +136,7 @@ export const FieldToolbar = React.memo((props: FieldToolbarProps) => {
commandBarButtonAs: () => (
<TooltipFunctionButton
key="function"
ariaLabel={formatMessage('Insert an adaptive expression pre-built function')}
dismissHandlerClassName={dismissHandlerClassName}
payload={functionRefPayload}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const svgIconStyle = { fill: FluentTheme.palette.neutralPrimary, margin: '0 4px'
const iconStyles = { root: { color: FluentTheme.palette.neutralPrimary, margin: '0 4px', width: 16, height: 16 } };

type ToolbarButtonMenuProps = {
ariaLabel: string;
payload: ToolbarButtonPayload;
disabled?: boolean;

Expand Down Expand Up @@ -138,7 +139,7 @@ const TooltipItem = React.memo(({ text, tooltip }: { text?: string; tooltip?: st
});

export const ToolbarButtonMenu = React.memo((props: ToolbarButtonMenuProps) => {
const { payload, disabled = false, dismissHandlerClassName = jsLgToolbarMenuClassName } = props;
const { payload, disabled = false, dismissHandlerClassName = jsLgToolbarMenuClassName, ariaLabel } = props;

const [propertyTreeExpanded, setPropertyTreeExpanded] = React.useState<Record<string, boolean>>({});
const uiStrings = React.useMemo(() => getStrings(payload.kind), [payload.kind]);
Expand Down Expand Up @@ -444,6 +445,7 @@ export const ToolbarButtonMenu = React.memo((props: ToolbarButtonMenuProps) => {

return (
<IconButton
aria-label={ariaLabel}
className={dismissHandlerClassName}
data-testid="menuButton"
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('<ToolbarButtonMenu />', () => {
* -------------------------------------------------
*/
it('template: Should render icon button with templates in the menu when passed template payload', async () => {
const component = render(<ToolbarButtonMenu payload={templatePayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={templatePayload} />);

expect(component).toBeTruthy();

Expand All @@ -67,7 +67,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('template: Should filter templates when passed query', async () => {
render(<ToolbarButtonMenu payload={templatePayload} />);
render(<ToolbarButtonMenu ariaLabel="test" payload={templatePayload} />);

fireEvent.click(screen.getByTestId('menuButton'));
fireEvent.change(screen.getByPlaceholderText('Search templates'), { target: { value: 'keyword' } });
Expand All @@ -80,7 +80,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('template: Should call onSelectCallback when a template is selected', async () => {
const component = render(<ToolbarButtonMenu payload={templatePayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={templatePayload} />);

expect(component).toBeTruthy();

Expand All @@ -97,7 +97,7 @@ describe('<ToolbarButtonMenu />', () => {
*/

it('property: Should render icon button with properties in menu when passed property payload', async () => {
const component = render(<ToolbarButtonMenu payload={propertiesPayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={propertiesPayload} />);

expect(component).toBeTruthy();

Expand All @@ -108,7 +108,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('property: Should filter properties when passed query', async () => {
render(<ToolbarButtonMenu payload={propertiesPayload} />);
render(<ToolbarButtonMenu ariaLabel="test" payload={propertiesPayload} />);

fireEvent.click(screen.getByTestId('menuButton'));
fireEvent.change(screen.getByPlaceholderText('Search properties'), { target: { value: 'this' } });
Expand All @@ -121,7 +121,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('property: Should expand property in the menu on click if not leaf', async () => {
render(<ToolbarButtonMenu payload={propertiesPayload} />);
render(<ToolbarButtonMenu ariaLabel="test" payload={propertiesPayload} />);

fireEvent.click(screen.getByTestId('menuButton'));
fireEvent.click(screen.getByText('this.'));
Expand All @@ -130,7 +130,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('property: Should call onSelectCallback when a leaf property is selected', async () => {
const component = render(<ToolbarButtonMenu payload={propertiesPayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={propertiesPayload} />);

expect(component).toBeTruthy();

Expand All @@ -148,7 +148,7 @@ describe('<ToolbarButtonMenu />', () => {
*/

it('function: Should render icon button with functions in menu when passed function payload', async () => {
const component = render(<ToolbarButtonMenu payload={functionPayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={functionPayload} />);

expect(component).toBeTruthy();

Expand All @@ -160,7 +160,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('function: Should show sub-menu when category is clicked from menu', async () => {
render(<ToolbarButtonMenu payload={functionPayload} />);
render(<ToolbarButtonMenu ariaLabel="test" payload={functionPayload} />);

fireEvent.click(screen.getByTestId('menuButton'));
fireEvent.click(screen.getByText(builtInFunctionsGrouping[0].name));
Expand All @@ -171,7 +171,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('function: Should filter functions when passed query', async () => {
render(<ToolbarButtonMenu payload={functionPayload} />);
render(<ToolbarButtonMenu ariaLabel="test" payload={functionPayload} />);

fireEvent.click(screen.getByTestId('menuButton'));
fireEvent.change(screen.getByPlaceholderText('Search functions'), { target: { value: 'string' } });
Expand All @@ -188,7 +188,7 @@ describe('<ToolbarButtonMenu />', () => {
});

it('function: Should call onSelectCallback when a function is selected', async () => {
const component = render(<ToolbarButtonMenu payload={functionPayload} />);
const component = render(<ToolbarButtonMenu ariaLabel="test" payload={functionPayload} />);

expect(component).toBeTruthy();

Expand Down