Navigation: a long tab fits its strip and cuts its label
CI / platforms (ubuntu-24.04) (push) Waiting to run
CI / crate (push) Failing after 28s
CI / site (push) Successful in 35s
CI / platforms (windows-latest) (push) Successful in 5m21s

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude committed 2026-10-18 22:10:52 -04:00
1 parent 3a68d1bb29
commit 7d704d97f4
2 files changed
+25 -2

No files matched your search

+5 -1
View File
@@ -182,6 +182,7 @@ impl RenderOnce for Tabs {
let value = tab.value.clone();
div()
.id(("tab", ix))
.debug_selector(move || format!("tab-{ix}"))
.role(Role::Tab)
.aria_selected(on)
.aria_label(tab.label.clone())
@@ -231,7 +232,10 @@ impl RenderOnce for Tabs {
.when(compact, |item| {
item.tooltip(Tooltip::text(tab.label.clone()))
})
.when(!compact, |item| item.child(tab.label.clone()))
.when(axis == Axis::Horizontal, |item| item.max_w_full())
.when(!compact, |item| {
item.child(div().min_w_0().truncate().child(tab.label.clone()))
})
.when_some(tab.note.clone().filter(|_| !compact), |item, note| {
item.child(div().text_color(colors.fg_subtle).child(note))
})
+20 -1
View File
@@ -185,12 +185,14 @@ struct Sheets {
chosen: SharedString,
clicked: Option<SharedString>,
width: f32,
long: bool,
}
impl Render for Sheets {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
let tabs = (0..30).map(|ix| Choice::new(format!("s{ix}"), format!("Sheet {ix}")));
let tail = if self.long { "W".repeat(40) } else { String::new() };
let tabs = (0..30).map(|ix| Choice::new(format!("s{ix}"), format!("Sheet {ix}{tail}")));
div()
.w(px(self.width))
.child(
@@ -218,6 +220,7 @@ fn a_wide_strip_scrolls_its_chosen_tab_in_and_the_wheel_reaches_the_rest(cx: &mu
chosen: "s29".into(),
clicked: None,
width: 300.0,
long: false,
});
settle(cx);
assert!(
@@ -252,6 +255,7 @@ fn a_strip_that_narrows_keeps_its_chosen_tab_in_view(cx: &mut TestAppContext) {
chosen: "s29".into(),
clicked: None,
width: 700.0,
long: false,
});
settle(cx);
view.update(cx, |view, cx| {
@@ -265,3 +269,18 @@ fn a_strip_that_narrows_keeps_its_chosen_tab_in_view(cx: &mut TestAppContext) {
let clicked = view.read_with(cx, |view, _| view.clicked.clone());
assert_eq!(clicked, None, "the chosen tab ends the strip");
}
#[gpui::test]
fn a_long_chosen_tab_fits_the_strip(cx: &mut TestAppContext) {
setup(cx);
let (_view, cx) = cx.add_window_view(|_, _| Sheets {
chosen: "s29".into(),
clicked: None,
width: 250.0,
long: true,
});
settle(cx);
let tab = cx.debug_bounds("tab-29").expect("the chosen tab");
assert!(tab.left() >= px(0.0), "starts in view: {tab:?}");
assert!(tab.right() <= px(250.0), "ends in view: {tab:?}");
}