Skip to content

fix(Card): items support for action - #245

Open
atakanbayrak wants to merge 9 commits into
mainfrom
fix/card_dropdown_action_addition
Open

atakanbayrak wants to merge 9 commits into
mainfrom
fix/card_dropdown_action_addition

Conversation

@atakanbayrak

Copy link
Copy Markdown
Contributor

Description

Dropdown feature is added inside Card.

Type of Change

  • 🆕 New Component
  • ✨ Feature / Enhancement
  • 🐛 Bug Fix
  • 💥 Breaking Change
  • 📦 Build / Dependency / Docs Update
  • 🧹 Code Refactoring

Screenshots / Preview

image

Checklist

  • Self-reviewed, no leftover logs or debug code
  • Uses design tokens — no hardcoded style values
  • Accessible (keyboard nav, ARIA, contrast)
  • Tests added/updated and passing
  • Storybook story added/updated

How to Test

  <div style={{ display: "flex", gap: 20, maxWidth: 800 }}>
        <Card
          title="Metin Tekin"
          subtitle="metintekin@motifui.com"
          avatarText="MT"
          contentText="The action at the top right opens a dropdown menu when it has items."
          action={{
            icon: "more_vert",
            items: [
              { label: "Profile", icon: "person", action: () => console.log("Profile clicked!") },
              { label: "Settings", icon: "settings", action: () => console.log("Settings clicked!") },
              { label: "Sign out", icon: "logout", action: () => console.log("Sign out clicked!") },
            ],
          }}
        />
        <Card
          title="Plain action"
          subtitle="onClick instead of items"
          avatarIcon="folder"
          contentText="The action at the top right runs its onClick as before."
          action={{ icon: "download", onClick: () => console.log("Download clicked!") }}
        />
      </div>

@claude

claude Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @aktasmehmet's task in 23s —— View job


Review of PR #245: Card action dropdown

I read the diff against the rules in docs/review/general.md, tests.md and css.md. figma.md and design-tokens.md don't apply: Card still uses the old --theme-* / --base-sizing-* layer. I did not run tests, tsc or lint, since CI covers them.

Blocking: none.

  • .Root is still compiled and is still the first rule. Only SCSS variables come before it (css.md §0).
  • The new .dropdown, .dropdownList, .dropdownHeader and .dropdownItem rules are flat BEM elements, with no !important, no ID selectors and shallow nesting (css.md §1–3).
  • The caret centering fix from the earlier review is in. The stale-comment note is also resolved, because the comment is gone.

Notes (non-blocking):

  • Duplication with Dropdown. This is the open thread with @hatesalp: the menu markup and styles duplicate Dropdown's (overlay, items, caret). The trade-off, avoiding coupling Card to Dropdown's module, is reasonable. Whichever way the team decides, the item type is the follow-up. CardDropdownItem mirrors DropdownMenuItemProps except onClick vs action, so the same item has two names across components. If the custom menu stays, I'd record the reason in a short comment so it isn't "fixed" later.
  • header items. In CardHeader.tsx, an item with both header and label/icon renders only the header and silently drops the rest. A discriminated type ({ header } | { label?, icon?, … }) would make that impossible to write.
  • Tests (Card.test.tsx). The open/close-on-item-click and disabled cases are covered. The Escape and outside-click closing, which the hook is configured for, are not. These are cheap to add. The new tests are not default-prop checks, so tests.md §1 is unaffected.
  • Story. The "Edit" item uses the settings icon (already raised in an earlier comment). edit would match the label.

The code is otherwise correct and the typing is sound. The onClick / items union with never prevents mixing the two forms, and existing onClick-only usages stay valid.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Size Change: +1.39 kB (+0.49%)

Total Size: 285 kB

📦 View Changed
Filename Size Change
dist/index.cjs 142 kB +680 B (+0.48%)
dist/index.es.js 141 kB +707 B (+0.5%)
ℹ️ View Unchanged
Filename Size
dist/chunks/useToggle-1pe2WRaw.js 800 B
dist/chunks/useToggle-B6kbi656.cjs 769 B
dist/hooks.cjs 225 B
dist/hooks.es.js 219 B

compressed-size-action

)}
{menuItems &&
attached &&
createPortal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@atakanbayrak atakanbayrak Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This matches DropdownMenuItemProps except onClick vs action. Can we share one type so the same item has one name across components?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/lib/components/Card/types.ts Resolved
@aktasmehmet
aktasmehmet requested a review from a team November 30, 2026 11:24
Comment on lines +86 to +101
<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>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be a seperate component

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need for the comment

Comment on lines +17 to +19
export type CardHeaderAction = { icon: IconGlobalType } & (
{ onClick: (event: MouseEvent<HTMLButtonElement>) => void; items?: never } | { items: CardDropdownItem[]; onClick?: never }
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +10 to +11
iconColor?: string;
header?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll check this file seperately after other threads are resolved

This branch is waiting to be deployed

1 waiting deployment
development — e4c5af00 Waiting Nov 30, 2026 by aktasmehmet via Chromatic #573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants