Skip to content

Commit

Permalink
a11y: make focus visible on create node button (#2677)
Browse files Browse the repository at this point in the history
* add circle outline for add button

* add set menuSelected false callback

Co-authored-by: Andy Brown <asbrown002@gmail.com>
Co-authored-by: Corina <14900841+corinagum@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 17, 2020
1 parent 4e6de94 commit 836d0fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/** @jsx jsx */
import { jsx, css } from '@emotion/core';
import { useCallback, useContext } from 'react';
import { useCallback, useContext, useState } from 'react';
import classnames from 'classnames';
import formatMessage from 'format-message';
import { createStepMenu, DialogGroup, SDKKinds } from '@bfc/shared';
Expand All @@ -16,6 +16,7 @@ import { SelectionContext } from '../../store/SelectionContext';
import { SelfHostContext } from '../../store/SelfHostContext';
import { AttrNames } from '../../constants/ElementAttributes';
import { MenuTypes } from '../../constants/MenuTypes';
import { ObiColors } from '../../constants/ElementColors';

import { IconMenu } from './IconMenu';

Expand Down Expand Up @@ -115,8 +116,14 @@ export const EdgeMenu: React.FC<EdgeMenuProps> = ({ id, addCoachMarkRef, onClick
};
};

const [menuSelected, setMenuSelected] = useState<boolean>(false);
const addRef = useCallback((action: HTMLDivElement) => addCoachMarkRef && addCoachMarkRef({ action }), []);
let boxShaow = '0px 2px 8px rgba(0, 0, 0, 0.1)';
boxShaow += menuSelected ? `,0 0 0 2px ${ObiColors.AzureBlue}` : nodeSelected ? `, 0 0 0 2px ${ObiColors.Black}` : '';

const handleMenuShow = menuSelected => {
setMenuSelected(menuSelected);
};
return (
<div
ref={addRef}
Expand All @@ -125,10 +132,9 @@ export const EdgeMenu: React.FC<EdgeMenuProps> = ({ id, addCoachMarkRef, onClick
height: EdgeAddButtonSize.height,
borderRadius: '8px',
backdropFilter: 'white',
boxShadow: '0px 2px 8px rgba(0, 0, 0, 0.1)',
boxShadow: boxShaow,
overflow: 'hidden',
background: 'white',
outline: nodeSelected ? '1px solid #0078d4' : '',
}}
className={classnames({ 'step-renderer-container--selected': nodeSelected })}
{...declareElementAttributes(id)}
Expand Down Expand Up @@ -157,6 +163,7 @@ export const EdgeMenu: React.FC<EdgeMenuProps> = ({ id, addCoachMarkRef, onClick
selfHosted ? x => x !== SDKKinds.LogAction : undefined
)}
label={formatMessage('Add')}
handleMenuShow={handleMenuShow}
{...rest}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IconMenuProps {
label?: string;
menuItems: any[];
menuWidth?: number;
handleMenuShow?: (menuShowed: boolean) => void;
}

export const IconMenu: React.FC<IconMenuProps> = ({
Expand All @@ -31,6 +32,7 @@ export const IconMenu: React.FC<IconMenuProps> = ({
label,
menuItems,
menuWidth,
handleMenuShow,
...rest
}): JSX.Element => {
const _onRenderItem = (item): React.ReactNode => {
Expand Down Expand Up @@ -78,6 +80,12 @@ export const IconMenu: React.FC<IconMenuProps> = ({
},
};

const onMenuClick = () => {
handleMenuShow && handleMenuShow(true);
};
const onAfterMenuDismiss = () => {
handleMenuShow && handleMenuShow(false);
};
return (
<IconButton
// @ts-ignore
Expand All @@ -86,6 +94,8 @@ export const IconMenu: React.FC<IconMenuProps> = ({
styles={buttonStyles}
menuIconProps={{ iconName, style: { fontSize: iconSize, fontWeight: 'bold', color } }}
menuProps={{ items: overflowItems, calloutProps: { calloutMaxWidth: menuWidth } }}
onMenuClick={onMenuClick}
onAfterMenuDismiss={onAfterMenuDismiss}
ariaLabel={label}
{...rest}
/>
Expand Down

0 comments on commit 836d0fe

Please sign in to comment.