fix: padding_right() should set right padding instead of left (#1837)

Fixes https://github.com/ratatui/ratatui/issues/1836
This commit is contained in:
三咲雅 · Misaki Masa 2025-05-10 14:31:16 +08:00 committed by GitHub
parent 60a81913ed
commit c238aca83a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -347,7 +347,7 @@ impl<'a> Tabs<'a> {
where
T: Into<Line<'a>>,
{
self.padding_left = padding.into();
self.padding_right = padding.into();
self
}
}
@ -553,6 +553,24 @@ mod tests {
test_case(tabs, Rect::new(0, 0, 30, 1), &expected);
}
#[test]
fn render_left_padding() {
let tabs = Tabs::new(vec!["Tab1", "Tab2", "Tab3", "Tab4"]).padding_left("---");
let mut expected = Buffer::with_lines(["---Tab1 │---Tab2 │---Tab3 │---Tab4 "]);
// first tab selected
expected.set_style(Rect::new(3, 0, 4, 1), DEFAULT_HIGHLIGHT_STYLE);
test_case(tabs, Rect::new(0, 0, 40, 1), &expected);
}
#[test]
fn render_right_padding() {
let tabs = Tabs::new(vec!["Tab1", "Tab2", "Tab3", "Tab4"]).padding_right("++");
let mut expected = Buffer::with_lines([" Tab1++│ Tab2++│ Tab3++│ Tab4++ "]);
// first tab selected
expected.set_style(Rect::new(1, 0, 4, 1), DEFAULT_HIGHLIGHT_STYLE);
test_case(tabs, Rect::new(0, 0, 40, 1), &expected);
}
#[test]
fn render_more_padding() {
let tabs = Tabs::new(vec!["Tab1", "Tab2", "Tab3", "Tab4"]).padding("---", "++");