Skip to content

Commit

Permalink
resolve comments and update screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny committed Oct 3, 2023
1 parent 8805f8b commit a9890f2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 4 additions & 13 deletions src/__stories__/menu-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ type MenuArgs = {
checkbox: boolean;
};

const getMenuItemControlProps = (withCheckbox: boolean, checked: boolean) => {
return withCheckbox
? {
controlType: 'checkbox' as const,
checked,
}
: {};
};

export const Default: StoryComponent<MenuArgs> = ({
menuOptionsCount,
horizontalPosition,
Expand Down Expand Up @@ -100,10 +91,10 @@ export const Default: StoryComponent<MenuArgs> = ({
alert({title: value, message: 'pressed'});
}
}}
{...getMenuItemControlProps(
checkbox,
valuesState.includes(`Option ${optionIndex + 1}`)
)}
{...(checkbox && {
controlType: 'checkbox' as const,
checked: valuesState.includes(`Option ${optionIndex + 1}`),
})}
Icon={icon ? IconLightningRegular : undefined}
/>
))}
Expand Down
13 changes: 7 additions & 6 deletions src/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Checkbox from './checkbox';
import {CSSTransition} from 'react-transition-group';
import {combineRefs} from './utils/common';

import type {ExclusifyUnion} from './utils/utility-types';
import type {DataAttributes, IconProps} from './utils/types';

const MENU_TRANSITION_DURATION_IN_MS = 120;
Expand All @@ -27,21 +28,22 @@ type MenuContextType = {
setFocusedValue: (value: string | null) => void;
closeMenu: () => void;
};

const MenuContext = React.createContext<MenuContextType>({
focusedValue: null,
isMenuOpen: false,
setFocusedValue: () => {},
closeMenu: () => {},
});
export const useMenuContext = (): MenuContextType => React.useContext(MenuContext);

const useMenuContext = (): MenuContextType => React.useContext(MenuContext);

interface MenuItemBaseProps {
label: string;
Icon?: React.FC<IconProps>;
destructive?: boolean;
disabled?: boolean;
'aria-label'?: string;
children?: undefined;
onPress: (label: string) => void;
}

Expand All @@ -51,18 +53,17 @@ interface MenuItemWithoutControlProps extends MenuItemBaseProps {
}

interface MenuItemWithControlProps extends MenuItemBaseProps {
controlType: 'checkbox';
controlType?: 'checkbox';
checked?: boolean;
}

type MenuItemProps = MenuItemWithControlProps | MenuItemWithoutControlProps;
type MenuItemProps = ExclusifyUnion<MenuItemWithControlProps | MenuItemWithoutControlProps>;

export const MenuItem: React.FC<MenuItemProps> = ({
label,
Icon,
destructive,
disabled,
'aria-label': ariaLabel,
onPress,
controlType,
checked,
Expand All @@ -83,7 +84,7 @@ export const MenuItem: React.FC<MenuItemProps> = ({
}}
disabled={disabled}
role="menuitemcheckbox"
aria-label={ariaLabel ?? label}
aria-label={label}
render={({controlElement}) => (
<Box paddingX={8} paddingY={12}>
<Inline space="between" alignItems="center">
Expand Down
1 change: 0 additions & 1 deletion src/overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const Overlay: React.FC<Props> = ({
className={className}
onPointerDown={(e) => {
// We use listen to and cancel pointerdown to close overlay if user scrolls on iOS.
// In Android with children we hide children and onPress later in onClick to ensure click event doesn't hit element below overlay.
if ((e.target as any).dataset.overlay && onPress) {
if (children && isAndroid(platformOverrides) && isChrome(platformOverrides)) {
e.stopPropagation();
Expand Down
2 changes: 1 addition & 1 deletion src/touchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const RawTouchable = React.forwardRef<TouchableElement, Props>((props, ref) => {
style: props.style,
role: props.role,
'aria-checked': props['aria-checked'],
'aria-disabled': props.disabled,
'aria-disabled': props.disabled ? true : undefined,
'aria-controls': props['aria-controls'],
'aria-expanded': props['aria-expanded'],
'aria-hidden': props['aria-hidden'],
Expand Down

0 comments on commit a9890f2

Please sign in to comment.