Skip to content

Commit

Permalink
Collapse UserSettings tabs to just icons on narrow screens (#12505)
Browse files Browse the repository at this point in the history
* Collapse UserSettings tabs to just icons on narrow screens

* Add screenshot test

* Better comment formatting.

Co-authored-by: Richard van der Hoff <[email protected]>

* Comment the media query

Co-authored-by: Richard van der Hoff <[email protected]>

---------

Co-authored-by: Richard van der Hoff <[email protected]>
  • Loading branch information
dbkr and richvdh authored May 10, 2024
1 parent c6f6f1d commit 948435c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions playwright/e2e/settings/general-user-settings-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ test.describe("General user settings tab", () => {
);
});

test("should respond to small screen sizes", async ({ page, uut }) => {
await page.setViewportSize({ width: 700, height: 600 });
await expect(uut).toMatchScreenshot("general-smallscreen.png");
});

test("should support adding and removing a profile picture", async ({ uut }) => {
const profileSettings = uut.locator(".mx_ProfileSettings");
// Upload a picture
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions res/css/structures/_TabbedView.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ limitations under the License.
padding-inline: var(--cpd-space-3x) var(--cpd-space-4x);
box-sizing: border-box;
min-block-size: 40px;
min-inline-size: 40px;
border-radius: 24px;
font: var(--cpd-font-body-md-medium);
position: relative;
Expand Down Expand Up @@ -164,3 +165,25 @@ limitations under the License.
overflow: auto;
min-height: 0; /* firefox */
}

/* Hide the labels on tabs, showing only the icons, on narrow viewports. */
@media (max-width: 768px) {
.mx_TabbedView_tabsOnLeft.mx_TabbedView_responsive {
.mx_TabbedView_tabLabel_text {
display: none;
}
.mx_TabbedView_tabPanel {
margin-left: 72px; /* 40px sidebar + 32px padding */
}
.mx_TabbedView_maskedIcon {
margin-right: auto;
margin-left: auto;
}
.mx_TabbedView_tabLabels {
width: auto;
}
.mx_TabbedView_tabLabel {
padding-inline: 0 0;
}
}
}
8 changes: 8 additions & 0 deletions src/components/structures/TabbedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ interface IProps<T extends string> {
onChange: (tabId: T) => void;
// The screen name to report to Posthog.
screenName?: ScreenName;
/**
* If true, the layout of the tabbed view will be responsive to the viewport size (eg, just showing icons
* instead of names of tabs).
* Only applies if `tabLocation === TabLocation.LEFT`.
* Default: false.
*/
responsive?: boolean;
}

/**
Expand Down Expand Up @@ -160,6 +167,7 @@ export default function TabbedView<T extends string>(props: IProps<T>): JSX.Elem
mx_TabbedView: true,
mx_TabbedView_tabsOnLeft: tabLocation == TabLocation.LEFT,
mx_TabbedView_tabsOnTop: tabLocation == TabLocation.TOP,
mx_TabbedView_responsive: props.responsive,
});

const screenName = tab?.screenName ?? props.screenName;
Expand Down
1 change: 1 addition & 0 deletions src/components/views/dialogs/UserSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
activeTabId={activeTabId}
screenName="UserSettings"
onChange={setActiveTabId}
responsive={true}
/>
</div>
</BaseDialog>
Expand Down

0 comments on commit 948435c

Please sign in to comment.