Repository navigation
fix(Card): items support for action - #245
atakanbayrak wants to merge 9 commits into
Conversation
|
Claude finished @aktasmehmet's task in 23s —— View job Review of PR #245: Card action dropdownI read the diff against the rules in Blocking: none.
Notes (non-blocking):
The code is otherwise correct and the typing is sound. The |
|
Size Change: +1.39 kB (+0.49%) Total Size: 285 kB 📦 View Changed
ℹ️ View Unchanged
|
| )} | ||
| {menuItems && | ||
| attached && | ||
| createPortal( |
There was a problem hiding this comment.
This menu duplicates Dropdown's (overlay, items, caret styles). Could we extract Dropdown's menu into a DropdownMenu that takes an anchorRef, and use it here with the IconButton? We can talk it over with the team.
There was a problem hiding this comment.
I implemented this dropdown actions as you mentioned in here at first actually, but Card component became so highly-coupled to Dropdown and its module, so custom dropdown behaved structure is implemented in here. We talked with @aktasmehmet, but he didn't see the code yet so maybe his opinion will be same with yours. Let's discuss this in here. @motif-ui/core-team
| import { LinkProps } from "../Link/types"; | ||
| import { IconButtonProps } from "../IconButton/types"; | ||
|
|
||
| export type CardDropdownItem = { |
There was a problem hiding this comment.
This matches DropdownMenuItemProps except onClick vs action. Can we share one type so the same item has one name across components?
There was a problem hiding this comment.
If we decide to keep separate custom Dropdown structure, we shouldn't create one type for this case. On the other hand, if we decide to use Dropdown this type will be removed anyway.
…ropdown_action_addition
| <div className={menuClassNames} style={menuStyle} ref={menuRef} {...insideProps} data-testid="cardDropdown"> | ||
| <ul className={styles.dropdownList}> | ||
| {menuItems.map((item, index) => ( | ||
| <li key={index}> | ||
| {item.header ? ( | ||
| <span className={styles.dropdownHeader}>{item.header}</span> | ||
| ) : ( | ||
| <button type="button" className={styles.dropdownItem} disabled={item.disabled} onClick={handleItemClick(item)}> | ||
| {item.icon && <GlobalIconWrapper icon={item.icon} style={{ color: item.iconColor }} />} | ||
| {item.label && <span>{item.label}</span>} | ||
| </button> | ||
| )} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div>, |
There was a problem hiding this comment.
This should be a seperate component
There was a problem hiding this comment.
In fact, I would create a hook here which also handles all the overlay stuff inside and return this part as component and actionRef to use inside ref of the icon button. This way, it will be much cleaner.
| expect(screen.queryByTestId("cardDropdown")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("should not run the click of a disabled dropdown item", () => { |
There was a problem hiding this comment.
| it("should not run the click of a disabled dropdown item", () => { | |
| it("should not fire on click of the action items which has its disabled prop as true ", () => { |
| expect(onClick).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should open a dropdown with the given items when the action has items and close it after an item is clicked", () => { |
There was a problem hiding this comment.
What about the outside click? close on escape (In fact if you did not activate this, please activate in the code)
| disabled?: boolean; | ||
| }; | ||
|
|
||
| /** The action at the top right: an icon button that runs onClick, or opens a dropdown with the given items */ |
There was a problem hiding this comment.
no need for the comment
| export type CardHeaderAction = { icon: IconGlobalType } & ( | ||
| { onClick: (event: MouseEvent<HTMLButtonElement>) => void; items?: never } | { items: CardDropdownItem[]; onClick?: never } | ||
| ); |
There was a problem hiding this comment.
Why do you prevent user having an onClick event when there are items? It might be possible for user to execute a code block when the dropdown opens. So, I suggest:
export type CardHeaderAction = {
icon: IconGlobalType;
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
items?: CardDropdownItem[];
};
and please move this right before CardVariant. It looks like the main type of the component (which is not) at the very top.
| iconColor?: string; | ||
| header?: string; |
There was a problem hiding this comment.
These 2 props are not necessary right now. They make it more complicated (like usage of header and label, icon, disabled, etc. together.). IconColor is a completely different thing. We dont provide such deep styling prop.
So, please remove both.
There was a problem hiding this comment.
And dont forget the jsdoc comment for this type below 😉
| // Action Dropdown: rendered in document.body, so it is not nested in the card | ||
| // ============================================================================= | ||
|
|
||
| .dropdown { |
There was a problem hiding this comment.
I'll check this file seperately after other threads are resolved
Description
Dropdown feature is added inside Card.
Type of Change
Screenshots / Preview
Checklist
How to Test