lipgloss icon indicating copy to clipboard operation
lipgloss copied to clipboard

BorderStyle without sides specified breaks size getters

Open alexanderbh opened this issue 7 months ago • 1 comments

Describe the bug If I set a border style with .BorderStyle() (ie, without the "sides") https://github.com/charmbracelet/lipgloss/blob/v2-exp/set.go#L449

As it says I do not specify sides as with the .Border() setter but all sides will be enabled during render which happens here: https://github.com/charmbracelet/lipgloss/blob/v2-exp/borders.go#L307

Which is fair. That is a nice default.

My issue then is that none of the sizing methods work. So if I ask horizontal border size it checks if a left or right border has been set. Here is the Left side for example: https://github.com/charmbracelet/lipgloss/blob/v2-exp/get.go#L314

But this will return 0 in the case where I only used .BorderStyle and borderLeftKey is not set explicitly.

To Reproduce Pseudocode:

s := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder())
s.getHorizontalBorderSize() // This returns 0 but the style will render a border

Expected behavior Either not setting the "sides" on the border should not show it, but that would be a breaking change. So the other option is to fix the sizing calculations in the case of "no sides" set but a style is set.

Workaround Use the .Border instead:

s := lipgloss.NewStyle().Border(lipgloss.NormalBorder(), true, true, true, true)
s.getHorizontalBorderSize() // This returns 2 yay

alexanderbh avatar May 04 '25 19:05 alexanderbh

Check which version you are using. I think this test shows exactly your case, and it is working as expected:

https://github.com/charmbracelet/lipgloss/blob/e729228ac14e63057e615a2241ce4303d59fef08/borders_test.go#L54-L59

It's the same on 1.1.0 https://github.com/charmbracelet/lipgloss/blob/v1.1.0/borders_test.go#L54-L59

maciej-sz avatar Jun 16 '25 20:06 maciej-sz