tabs: add overflow scroll option for horizontal scrolling
This commit is contained in:
+19
-1
@@ -108,6 +108,7 @@ pub struct Tabs {
|
||||
id: ElementId,
|
||||
selected: usize,
|
||||
variant: TabsVariant,
|
||||
overflow_scroll: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler>,
|
||||
on_close: Option<CloseHandler>,
|
||||
@@ -124,6 +125,7 @@ impl Tabs {
|
||||
id: id.into(),
|
||||
selected: 0,
|
||||
variant: TabsVariant::default(),
|
||||
overflow_scroll: false,
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
on_close: None,
|
||||
@@ -143,6 +145,12 @@ impl Tabs {
|
||||
self
|
||||
}
|
||||
|
||||
/// Scrolls the strip horizontally when the tabs overflow.
|
||||
pub fn overflow_scroll(mut self, overflow_scroll: bool) -> Self {
|
||||
self.overflow_scroll = overflow_scroll;
|
||||
self
|
||||
}
|
||||
|
||||
/// Reports the next selected tab, as an index into the `tabs` vec — not a tab key; indices shift on reorder.
|
||||
pub fn on_change<F>(mut self, handler: F) -> Self
|
||||
where
|
||||
@@ -254,7 +262,17 @@ impl RenderOnce for Tabs {
|
||||
}
|
||||
TabsVariant::Pill => root.items_center().gap_1(),
|
||||
})
|
||||
.children(strip)
|
||||
.map(|root| match self.overflow_scroll {
|
||||
true => root.min_w_0().overflow_x_scroll().child(
|
||||
div()
|
||||
.flex_none()
|
||||
.flex()
|
||||
.gap_1()
|
||||
.when(self.variant == TabsVariant::Pill, |row| row.items_center())
|
||||
.children(strip),
|
||||
),
|
||||
false => root.children(strip),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user