Skip to content

Commit

Permalink
Dropdown Expandable - QA review fixing disabled states (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-cedrone-cengage authored Oct 19, 2023
1 parent 6960285 commit 68276ab
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .changeset/fix-expandableDropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'react-magma-dom': patch
---

fix(Dropdown): Fixes from QA review of the Dropdown Expandable sub component.
fix(Dropdown): Fixes from QA review of the Dropdown Expandable sub component disabled states.
5 changes: 5 additions & 0 deletions .changeset/fix-expandableDropdownDisabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': patch
---

feat(DropdownExpandableMenu): A new menu item display for the Dropdown component which enables expandable lists by one level.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export const ExpandableItemsWithIcons = args => {
DropdownExpandableMenuButton component
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownExpandableMenuListItem>
<DropdownExpandableMenuListItem disabled>
Fresh
</DropdownExpandableMenuListItem>
<DropdownExpandableMenuListItem>
Expand Down
32 changes: 32 additions & 0 deletions packages/react-magma-dom/src/components/Dropdown/Dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,38 @@ describe('Dropdown', () => {
);
});

it(`DropdownExpandableMenuListItem should support disabled`, () => {
const { getByText } = render(
<Dropdown>
<DropdownButton>Expandable Items Dropdown</DropdownButton>
<DropdownContent>
<DropdownExpandableMenuGroup>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton>
Pasta
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownExpandableMenuListItem disabled>
Fresh
</DropdownExpandableMenuListItem>
<DropdownExpandableMenuListItem>
Processed
</DropdownExpandableMenuListItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
</DropdownExpandableMenuGroup>
</DropdownContent>
</Dropdown>
);
fireEvent.click(getByText('Pasta'));

expect(getByText('Fresh')).toHaveStyleRule('cursor', 'not-allowed');
expect(getByText('Fresh')).toHaveStyleRule(
'color',
transparentize(0.4, magma.colors.neutral500)
);
});

it(`DropdownExpandableMenuPanel items should have additional padding if DropdownExpandableMenuButton has an icon and a text only menu item`, () => {
const { getByTestId, getByText } = render(
<Dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DropdownExpandableMenuButtonProps
const StyledAccordionButton = styled(AccordionButton)<{
expandableMenuButtonHasIcon?: boolean;
icon?: React.ReactElement<IconProps>;
isMenuItemContextDisabled?: boolean;
}>`
font-weight: 400;
overflow-wrap: anywhere;
Expand All @@ -32,7 +33,8 @@ const StyledAccordionButton = styled(AccordionButton)<{
}
&:hover,
&:focus {
background: ${menuBackground};
background: ${props =>
props.isMenuItemContextDisabled ? '' : menuBackground};
}
> span {
display: flex;
Expand Down Expand Up @@ -86,6 +88,7 @@ export const DropdownExpandableMenuButton = React.forwardRef<
expandableMenuGroupContext.expandableMenuButtonHasIcon
}
isInverse={context.isInverse}
isMenuItemContextDisabled={expandableMenuItemContext.disabled}
testId={testId}
>
{icon && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { DropdownMenuItem, DropdownMenuItemProps } from './DropdownMenuItem';
import { DropdownExpandableMenuItemContext } from './DropdownExpandableMenuItem';

export interface DropdownExpandableMenuListItemProps
extends Omit<DropdownMenuItemProps, 'icon' | 'disabled'> {
extends Omit<DropdownMenuItemProps, 'icon'> {
disabled?: boolean;
testId?: string;
}

Expand All @@ -32,7 +33,7 @@ export const DropdownExpandableMenuListItem = React.forwardRef<
HTMLDivElement,
DropdownExpandableMenuListItemProps
>((props, forwardedRef) => {
const { children, ...other } = props;
const { children, disabled, ...other } = props;

const ownRef = React.useRef<HTMLDivElement>();
const theme = React.useContext(ThemeContext);
Expand All @@ -54,6 +55,7 @@ export const DropdownExpandableMenuListItem = React.forwardRef<
return (
<StyledDropdownMenuItem
{...other}
disabled={disabled}
expandableMenuButtonHasIcon={menuGroupContext.expandableMenuButtonHasIcon}
isExpandablePanel={menuGroupContext.isExpandablePanel}
ref={expandableMenuItemContext.disabled ? null : ref}
Expand Down

2 comments on commit 68276ab

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.