Skip to content

Update vscode-button to only apply a margin to icons if there is slotted content#425

Closed
a-stewart wants to merge 2 commits into
vscode-elements:mainfrom
a-stewart:only-margin-icon-if-slotted
Closed

Update vscode-button to only apply a margin to icons if there is slotted content#425
a-stewart wants to merge 2 commits into
vscode-elements:mainfrom
a-stewart:only-margin-icon-if-slotted

Conversation

@a-stewart
Copy link
Copy Markdown
Contributor

@a-stewart a-stewart commented May 13, 2025

If you have a button which includes an icon but no text, it still has the 3px margin - which results in the button being off centre

image

This change updates the CSS to only apply that 3px margin if there is slotted content.

image

As such for regular buttons this should be a noop, but for buttons which only specify an icon, it should correctly centre the icon in the button.


It also applies a height 100%, since if there is no content, this can also cause the button to get vertically squished if it is placed in a flex with other buttons.

@a-stewart
Copy link
Copy Markdown
Contributor Author

Also fixed the alignment if there are slotted elements, instead of just slotted text.

Slotted children are spaced by 4px, and there is a filter to remove that spacing before the first element but it is missing on the last element, resulting in

image

Left button includes two <vscode-icon>s in the slot, you can see the additional padding to the right.

Middle, just contains text, since this doesn't match any sltoted children, no margin is currently applied, so it is correctly centred.

Right contains the same text but wrapped in a span, that has the same issue as the icons where it has a margin right but not a margin left.

Adding a ::slotted(*:last-child) { margin-right: 0; } to remove the trailing margin to match the ::slotted(*:first-child) { margin-left: 0; } that already exists fixes this.

@a-stewart
Copy link
Copy Markdown
Contributor Author

a-stewart commented May 15, 2025

This fix is still valid standalone, but it is also included in #427

@bendera
Copy link
Copy Markdown
Member

bendera commented May 16, 2025

Closed as it's merged in #427

@bendera bendera closed this May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants