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

fix(dropdowns): add missing data-garden- attributes to menu item icon elements #1158

Merged
merged 2 commits into from
Jul 22, 2021
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
16 changes: 8 additions & 8 deletions packages/dropdowns/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"index.cjs.js": {
"bundled": 89862,
"minified": 55103,
"gzipped": 11601
"bundled": 89987,
"minified": 55212,
"gzipped": 11607
},
"index.esm.js": {
"bundled": 83481,
"minified": 49626,
"gzipped": 11274,
"bundled": 83606,
"minified": 49735,
"gzipped": 11289,
"treeshaked": {
"rollup": {
"code": 37445,
"code": 37524,
"import_statements": 813
},
"webpack": {
"code": 43832
"code": 43911
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/dropdowns/src/styled/items/StyledItemIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { math } from 'polished';
import { getColor, DEFAULT_THEME } from '@zendeskgarden/react-theming';
import { getItemPaddingVertical } from './StyledItem';

const COMPONENT_ID = 'dropdowns.item_icon';

interface IStyledItemIconProps {
isCompact?: boolean;
isVisible?: boolean;
Expand All @@ -23,7 +25,10 @@ const getSizeStyles = (props: IStyledItemIconProps & ThemeProps<DefaultTheme>) =
`;
};

export const StyledItemIcon = styled.div<IStyledItemIconProps>`
export const StyledItemIcon = styled.div.attrs({
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})<IStyledItemIconProps>`
display: flex;
position: absolute;
top: 0;
Expand Down
20 changes: 7 additions & 13 deletions packages/dropdowns/stories/examples/Menu/Advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import React, { useState } from 'react';
import React from 'react';
import { Story } from '@storybook/react';
import {
Dropdown,
Expand Down Expand Up @@ -46,29 +46,22 @@ interface IStoryProps {
isAnimated: boolean;
isCompact: boolean;
isDisabled: boolean;
isOpen: boolean;
}

export const Advanced: Story<IStoryProps> = ({
hasArrow,
isAnimated,
isCompact,
placement,
isDisabled
isDisabled,
isOpen
}) => {
const [isOpen, setIsOpen] = useState(false);

return (
<Grid>
<Row style={{ minHeight: 400 }}>
<Col textAlign="center">
<Dropdown
isOpen={isOpen}
onStateChange={changes => {
if (Object.prototype.hasOwnProperty.call(changes, 'isOpen')) {
setIsOpen(changes.isOpen === true);
}
}}
>
<Dropdown isOpen={isOpen || undefined}>
Copy link
Member Author

@jzempel jzempel Jul 22, 2021

Choose a reason for hiding this comment

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

I realize this treatment flips the component between controlled and uncontrolled (and results in a warning). But that's the point – the control demonstrates both uses. More importantly, we have the ability to observe and use dev tools to debug the menu items which is imperative for the storybook demo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a more suitable structure would be to demonstrate one of each usage per story β€” similar to the accordion stories. Probably not the right time for re-structuring, but just wanted to throw the idea out there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps. This directly copies the Default dropdowns story. So we may want to address both.

<Trigger>
<Button size={isCompact ? 'small' : 'medium'}>Advanced Layout</Button>
</Trigger>
Expand Down Expand Up @@ -157,7 +150,8 @@ Advanced.argTypes = {
]
}
},
isDisabled: { name: 'Disabled items', control: 'boolean' }
isDisabled: { name: 'Disabled items', control: 'boolean' },
isOpen: { control: 'boolean' }
};

Advanced.args = {
Expand Down