Skip to content

Commit

Permalink
improvement(DefaultToolWindows): improve overflow handling in header
Browse files Browse the repository at this point in the history
Tool window header (Tabs in most cases) should not be pushed, but should overflow out, when resizing to very small sizes.
  • Loading branch information
alirezamirian committed Dec 6, 2023
1 parent aec27b7 commit 23b885f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
12 changes: 6 additions & 6 deletions packages/jui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ declare global {
interface Chainable {
/**
* Custom command to perform resize action on an element with resize handle on `side`
* @example cy.resizeLeft('left', 50) // increase size by 50 pixels, using left resize handle.
* @example cy.resizeLeft('left', -50) // decrease size by 50 pixels, using left resize handle.
* @example cy.resizeLeft('top', 50) // increase size by 50 pixels, using top resize handle.
* @example cy.resizeLeft('top', -50) // decrease size by 50 pixels, using top resize handle.
* @example cy.resizeFromSide('left', 50) // increase size by 50 pixels, using left resize handle.
* @example cy.resizeFromSide('left', -50) // decrease size by 50 pixels, using left resize handle.
* @example cy.resizeFromSide('top', 50) // increase size by 50 pixels, using top resize handle.
* @example cy.resizeFromSide('top', -50) // decrease size by 50 pixels, using top resize handle.
*/
resize(
resizeFromSide(
side: "left" | "right" | "top" | "bottom",
value: number
): Chainable<JQuery<HTMLElement>>;
Expand All @@ -58,7 +58,7 @@ declare global {
}

Cypress.Commands.add(
"resize",
"resizeFromSide",
{ prevSubject: "element" },
(subject, side, value) => {
return cy
Expand Down
49 changes: 38 additions & 11 deletions packages/jui/src/Popup/Popup.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ describe("Popup", () => {
interactions="all"
/>
);
cy.get("#popup").resize("left", -50).invoke("width").should("eq", 100);
cy.get("#popup").resize("left", 50).invoke("width").should("eq", 150);
cy.get("#popup")
.resizeFromSide("left", -50)
.invoke("width")
.should("eq", 100);
cy.get("#popup")
.resizeFromSide("left", 50)
.invoke("width")
.should("eq", 150);
cy.wrap(onBoundsChange).should("be.calledTwice");
cy.wrap(onBoundsChange).should(
"be.calledWithMatch",
Expand All @@ -116,8 +122,14 @@ describe("Popup", () => {
interactions="all"
/>
);
cy.get("#popup").resize("right", -50).invoke("width").should("eq", 100);
cy.get("#popup").resize("right", 50).invoke("width").should("eq", 150);
cy.get("#popup")
.resizeFromSide("right", -50)
.invoke("width")
.should("eq", 100);
cy.get("#popup")
.resizeFromSide("right", 50)
.invoke("width")
.should("eq", 150);
cy.wrap(onBoundsChange).should("be.calledTwice");
cy.wrap(onBoundsChange).should(
"be.calledWithMatch",
Expand All @@ -139,8 +151,14 @@ describe("Popup", () => {
interactions="all"
/>
);
cy.get("#popup").resize("top", -50).invoke("height").should("eq", 100);
cy.get("#popup").resize("top", 50).invoke("height").should("eq", 150);
cy.get("#popup")
.resizeFromSide("top", -50)
.invoke("height")
.should("eq", 100);
cy.get("#popup")
.resizeFromSide("top", 50)
.invoke("height")
.should("eq", 150);
cy.wrap(onBoundsChange).should("be.calledTwice");
cy.wrap(onBoundsChange).should(
"be.calledWithMatch",
Expand All @@ -162,8 +180,14 @@ describe("Popup", () => {
interactions="all"
/>
);
cy.get("#popup").resize("bottom", -50).invoke("height").should("eq", 100);
cy.get("#popup").resize("bottom", 50).invoke("height").should("eq", 150);
cy.get("#popup")
.resizeFromSide("bottom", -50)
.invoke("height")
.should("eq", 100);
cy.get("#popup")
.resizeFromSide("bottom", 50)
.invoke("height")
.should("eq", 150);
cy.wrap(onBoundsChange).should("be.calledTwice");
cy.wrap(onBoundsChange).should(
"be.calledWithMatch",
Expand All @@ -187,7 +211,10 @@ describe("Popup", () => {
interactions="all"
/>
);
cy.get("#popup").resize("right", -40).invoke("width").should("eq", 130);
cy.get("#popup")
.resizeFromSide("right", -40)
.invoke("width")
.should("eq", 130);
cy.wrap(onBoundsChanging).should(
"be.calledOnceWith",
Cypress.sinon.match({ left: 50, top: 150, width: 130, height: 100 }),
Expand Down Expand Up @@ -224,7 +251,7 @@ describe("Popup", () => {
/>
);
cy.contains("Title").move(-50, 50);
cy.get("#popup").resize("bottom", -50);
cy.get("#popup").resizeFromSide("bottom", -50);
cy.get("#popup")
.invoke("offset")
.should("deep.equal", { left: 100, top: 100 });
Expand All @@ -242,7 +269,7 @@ describe("Popup", () => {
/>
);
cy.contains("Title").move(-50, 50);
cy.get("#popup").resize("left", 50).move(-50, 50);
cy.get("#popup").resizeFromSide("left", 50).move(-50, 50);
cy.get("#popup")
.invoke("offset")
.should("deep.equal", { left: 50, top: 150 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const StyledToolWindowHeaderContent = styled.div`
flex: 1;
display: flex;
align-items: center;
overflow: hidden;
`;

export const DefaultToolWindowHeader: React.FC<ToolWindowHeaderProps> = ({
Expand Down
22 changes: 19 additions & 3 deletions packages/jui/src/ToolWindowsImpl/DefaultToolWindows.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState } from "react";
import {
DefaultToolWindow,
DefaultToolWindows,
Theme,
ThemeProvider,
ToolWindowRefValue,
ToolWindowsState,
ToolWindowState,
toolWindowState,
DefaultToolWindows,
ToolWindowState,
} from "@intellij-platform/core";
import darculaThemeJson from "../../themes/darcula.theme.json";
import { KeymapProvider } from "@intellij-platform/core/ActionSystem";
Expand All @@ -17,7 +17,10 @@ const window = (id: string) => ({
title: id,
icon: null,
content: (
<DefaultToolWindow data-testid={`${id}`} headerContent={id}>
<DefaultToolWindow
data-testid={`${id}`}
headerContent={<span style={{ whiteSpace: "nowrap" }}>{id}</span>}
>
<input />
<input />
</DefaultToolWindow>
Expand Down Expand Up @@ -56,6 +59,19 @@ const SimpleToolWindows = React.forwardRef(
}
);

describe("DefaultToolWindowHeader", () => {
beforeEach(() => {
cy.viewport("macbook-13");
});
it("overflows the header title out, in small sizes, without pushing the content", () => {
cy.mount(<SimpleToolWindows />);
cy.findByTestId("First window").resizeFromSide("right", -150);
cy.percySnapshot("DefaultToolWindowHeader--overflow", {
scope: '[data-testid="First window"]',
});
});
});

describe("DefaultToolWindowActions", () => {
beforeEach(() => {
cy.viewport("macbook-13");
Expand Down

0 comments on commit 23b885f

Please sign in to comment.