Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion crates/story/src/stories/button_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gpui::{
};

use gpui_component::{
ActiveTheme, Disableable as _, Icon, IconName, Selectable as _, Sizable as _, Theme,
ActiveTheme, Disableable as _, Icon, IconName, Selectable as _, Sizable as _, Size, StyleSized,
Theme,
button::{Button, ButtonCustomVariant, ButtonGroup, ButtonVariants as _},
checkbox::Checkbox,
h_flex, v_flex,
Expand Down Expand Up @@ -906,5 +907,49 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
),
)
.child(
section("Button with different text size")
.child(
Button::new("button-custom-text-large")
.primary()
.label("Large")
.text_lg(),
)
.child(
Button::new("button-custom-text-medium")
.primary()
.label("Medium")
.button_text_size(Size::Medium),
)
.child(
Button::new("button-custom-text-small")
.primary()
.label("Small")
.text_sm(),
)
.child(
Button::new("button-custom-text-xsmall")
.primary()
.label("XSmall")
.button_text_size(Size::XSmall),
)
.child(
Button::new("button-custom-text-35")
.primary()
.label("35 px")
.button_text_size(Size::Size(px(35.0))),
)
.child(
Button::new("button-custom-text-8")
.primary()
.label("8 px")
.text_size(px(8.0)),
)
.child(
Button::new("button-custom-text-8")
.primary()
.label("Not Specified"),
),
)
}
}
3 changes: 1 addition & 2 deletions crates/ui/src/button/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::rc::Rc;

use crate::{
ActiveTheme, Colorize as _, Disableable, FocusableExt as _, Icon, IconName, Selectable,
Sizable, Size, StyleSized, StyledExt, h_flex, spinner::Spinner, tooltip::Tooltip,
Sizable, Size, StyledExt, h_flex, spinner::Spinner, tooltip::Tooltip,
};
use gpui::{
Action, AnyElement, App, ClickEvent, Corners, Div, Edges, ElementId, Hsla, InteractiveElement,
Expand Down Expand Up @@ -572,7 +572,6 @@ impl RenderOnce for Button {
.w_full()
.items_center()
.justify_center()
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing .button_text_size(self.size) here fixes the issue where custom text sizes were being overridden, but it creates a new problem: buttons that don't explicitly call .button_text_size() will no longer have appropriate default text sizes based on their size variant.

The proper fix requires applying .button_text_size(self.size) to self.base (around line 540, before .refine_style(&self.style)). This would ensure that:

  1. Buttons have default text sizes matching their size variant (XSmall → text_xs, Small → text_sm, Medium → text_base, Large → text_lg)
  2. Custom text sizes set via .button_text_size() on the Button instance override the default (since .refine_style() is applied after the default)

Without this default, existing buttons that rely on automatic size-appropriate text sizing will break.

Copilot uses AI. Check for mistakes.
.button_text_size(self.size)
.map(|this| match self.size {
Size::XSmall => this.gap_1(),
Size::Small => this.gap_1(),
Expand Down
4 changes: 3 additions & 1 deletion crates/ui/src/styled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ impl<T: Styled> StyleSized<T> for T {
match size {
Size::XSmall => self.text_xs(),
Size::Small => self.text_sm(),
_ => self.text_base(),
Size::Medium => self.text_base(),
Size::Large => self.text_lg(),
Copy link
Member

@huacnlee huacnlee Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large and custom size button should keep the text base.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I want to display small text inside a large button?

Size::Size(size) => self.text_size(size),
}
}
}
Expand Down