Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 948435c

Browse files
dbkrrichvdh
andauthored
Collapse UserSettings tabs to just icons on narrow screens (#12505)
* 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]>
1 parent c6f6f1d commit 948435c

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

playwright/e2e/settings/general-user-settings-tab.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ test.describe("General user settings tab", () => {
125125
);
126126
});
127127

128+
test("should respond to small screen sizes", async ({ page, uut }) => {
129+
await page.setViewportSize({ width: 700, height: 600 });
130+
await expect(uut).toMatchScreenshot("general-smallscreen.png");
131+
});
132+
128133
test("should support adding and removing a profile picture", async ({ uut }) => {
129134
const profileSettings = uut.locator(".mx_ProfileSettings");
130135
// Upload a picture
Loading

res/css/structures/_TabbedView.pcss

+23
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ limitations under the License.
129129
padding-inline: var(--cpd-space-3x) var(--cpd-space-4x);
130130
box-sizing: border-box;
131131
min-block-size: 40px;
132+
min-inline-size: 40px;
132133
border-radius: 24px;
133134
font: var(--cpd-font-body-md-medium);
134135
position: relative;
@@ -164,3 +165,25 @@ limitations under the License.
164165
overflow: auto;
165166
min-height: 0; /* firefox */
166167
}
168+
169+
/* Hide the labels on tabs, showing only the icons, on narrow viewports. */
170+
@media (max-width: 768px) {
171+
.mx_TabbedView_tabsOnLeft.mx_TabbedView_responsive {
172+
.mx_TabbedView_tabLabel_text {
173+
display: none;
174+
}
175+
.mx_TabbedView_tabPanel {
176+
margin-left: 72px; /* 40px sidebar + 32px padding */
177+
}
178+
.mx_TabbedView_maskedIcon {
179+
margin-right: auto;
180+
margin-left: auto;
181+
}
182+
.mx_TabbedView_tabLabels {
183+
width: auto;
184+
}
185+
.mx_TabbedView_tabLabel {
186+
padding-inline: 0 0;
187+
}
188+
}
189+
}

src/components/structures/TabbedView.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ interface IProps<T extends string> {
132132
onChange: (tabId: T) => void;
133133
// The screen name to report to Posthog.
134134
screenName?: ScreenName;
135+
/**
136+
* If true, the layout of the tabbed view will be responsive to the viewport size (eg, just showing icons
137+
* instead of names of tabs).
138+
* Only applies if `tabLocation === TabLocation.LEFT`.
139+
* Default: false.
140+
*/
141+
responsive?: boolean;
135142
}
136143

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

165173
const screenName = tab?.screenName ?? props.screenName;

src/components/views/dialogs/UserSettingsDialog.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
224224
activeTabId={activeTabId}
225225
screenName="UserSettings"
226226
onChange={setActiveTabId}
227+
responsive={true}
227228
/>
228229
</div>
229230
</BaseDialog>

0 commit comments

Comments
 (0)