Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fluffy-hotels-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"landscape-ui": patch
---

Keep icons in the collapsed buttons inside button dropdowns
14 changes: 14 additions & 0 deletions src/components/ui/ResponsiveButtons/ResponsiveButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,18 @@ describe("ResponsiveButtons", () => {
screen.getByRole("button", { name: "Disabled button" }),
).toHaveAttribute("aria-disabled");
});

it("preserves icon children in collapsed menu items", async () => {
setScreenSize("xs");

render(<ResponsiveButtons buttons={buttons} />);

await userEvent.click(screen.getByRole("button", { name: /actions/i }));

const buttonWithIcon = screen.getByRole("button", {
name: "Button with icon",
});

expect(buttonWithIcon.querySelector(".p-icon--code")).toBeInTheDocument();
});
});
6 changes: 5 additions & 1 deletion src/components/ui/ResponsiveButtons/ResponsiveButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ResponsiveButtons: FC<ResponsiveButtonGroupProps> = ({
}
}}
disabled={link.disabled}
hasIcon={link.hasIcon}
>
{link.children}
</Button>
Expand Down Expand Up @@ -99,9 +100,11 @@ const ResponsiveButtons: FC<ResponsiveButtonGroupProps> = ({

collapsed.push({
key: `action-${index}`,
children: textFromNode(el) || `Action ${index + 1}`,
children:
el.props.children || textFromNode(el) || `Action ${index + 1}`,
onClick: el.props.onClick,
disabled: el.props.disabled,
hasIcon: el.props.hasIcon,
Comment thread
gesquivelgaghi marked this conversation as resolved.
});

return;
Expand Down Expand Up @@ -185,6 +188,7 @@ const ResponsiveButtons: FC<ResponsiveButtonGroupProps> = ({
}
}}
disabled={item.disabled}
hasIcon={item.hasIcon}
>
{item.children}
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/components/ui/ResponsiveButtons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ButtonLikeProps {
className?: string;
"aria-label"?: string;
title?: string;
hasIcon?: boolean;
}

export interface ContextualMenuProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,35 @@ const InstancesPageActions = memo(function InstancesPageActions({
const proServicesLinks = [
allInstancesHaveToken
? {
children: <span>Replace token</span>,
children: (
<>
Comment thread
gesquivelgaghi marked this conversation as resolved.
<Icon name="change-version" />
<span>Replace token</span>
</>
),
onClick: handleReplaceToken,
hasIcon: true,
}
: {
children: <span>Attach token</span>,
children: (
<>
<Icon name="private-key" />
<span>Attach token</span>
</>
),
onClick: handleAttachToken,
hasIcon: true,
},
isFeatureEnabled("ubuntu_pro_licensing")
? {
children: <span>Detach token</span>,
children: (
<>
<Icon name="disconnect" />
<span>Detach token</span>
</>
),
onClick: openDetachModal,
hasIcon: true,
}
: {},
].filter((link) => link.children);
Expand All @@ -230,7 +248,7 @@ const InstancesPageActions = memo(function InstancesPageActions({
buttons={[
<Button
key="shutdown-instances"
className="has-icon"
hasIcon
type="button"
disabled={0 === selectedInstances.length || isGettingInstances}
onClick={openShutdownModal}
Expand All @@ -255,6 +273,7 @@ const InstancesPageActions = memo(function InstancesPageActions({
className="u-no-margin--bottom"
onClick={proServicesLinks[0].onClick}
disabled={0 === selectedInstances.length}
hasIcon={proServicesLinks[0].hasIcon}
>
{proServicesLinks[0].children}
</Button>
Expand All @@ -274,6 +293,7 @@ const InstancesPageActions = memo(function InstancesPageActions({
<Button
key="report-view"
type="button"
hasIcon
onClick={handleReportView}
disabled={0 === selectedInstances.length}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const PackageActions: FC<PackageActionsProps> = ({ selectedPackages }) => {
onClick={() => {
handleExistingPackages(packageAction);
}}
hasIcon
>
<Icon name={INSTALLED_PACKAGE_ACTIONS[packageAction].icon} />
<span>{INSTALLED_PACKAGE_ACTIONS[packageAction].label}</span>
Expand Down
5 changes: 5 additions & 0 deletions src/features/snaps/components/SnapsActions/SnapsActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

const handleEditSnap = (action: EditSnapType) => {
const count =
action === EditSnapType.Unhold

Check warning on line 37 in src/features/snaps/components/SnapsActions/SnapsActions.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Do not nest ternary expressions
? held
: action === EditSnapType.Hold
? unheld
Expand Down Expand Up @@ -81,6 +81,7 @@
onClick={() => {
handleEditSnap(EditSnapType.Switch);
}}
hasIcon
>
<Icon name="fork" />
<span>Switch channel</span>
Expand All @@ -94,6 +95,7 @@
onClick={() => {
handleEditSnap(EditSnapType.Uninstall);
}}
hasIcon
>
<Icon name={ICONS.delete} />
<span>Uninstall</span>
Expand All @@ -107,6 +109,7 @@
onClick={() => {
handleEditSnap(EditSnapType.Hold);
}}
hasIcon
>
<Icon name="pause" />
<span>Hold</span>
Expand All @@ -121,6 +124,7 @@
onClick={() => {
handleEditSnap(EditSnapType.Unhold);
}}
hasIcon
>
<Icon name="play" />
<span>Unhold</span>
Expand All @@ -134,6 +138,7 @@
onClick={() => {
handleEditSnap(EditSnapType.Refresh);
}}
hasIcon
>
<Icon name="change-version" />
<span>Refresh</span>
Expand Down
Loading