Skip to content

Commit

Permalink
[@mantine/core] Switch: Fix Switch shrinking when large label or desc…
Browse files Browse the repository at this point in the history
…ription is used (#6531)
  • Loading branch information
rtivital committed Aug 7, 2024
1 parent 5263671 commit 4a17e88
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
line-height: 0;
color: var(--switch-text-color);

&:where([data-without-labels]) {
width: var(--switch-width);
}

.input:focus-visible + & {
outline: 2px solid var(--mantine-primary-color-filled);
outline-offset: 2px;
Expand Down
32 changes: 30 additions & 2 deletions packages/@mantine/core/src/components/Switch/Switch.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IconBadge } from '@tabler/icons-react';
import { Box } from '../../core';
import { Group } from '../Group';
import { Stack } from '../Stack';
import { Switch } from './Switch';
Expand Down Expand Up @@ -119,6 +120,33 @@ export function WithError() {
);
}

export function Alignment() {
return <Switch />;
export function Shrinking() {
return (
<Box bg="blue.1" w={400}>
<Switch bg="green" value="svelte" label="Larger Switch" />
<Switch
bg="green"
value="react"
label="Same"
description="Short description - No Issue"
styles={{
labelWrapper: { backgroundColor: 'var(--mantine-color-green-2)' },
}}
/>
<Switch
styles={{
labelWrapper: { backgroundColor: 'var(--mantine-color-red-4)' },
}}
bg="red"
value="svelte"
label="Smaller"
description="Long description, You can see how the Switch is smaller :( Description has to be multiline"
/>
<Switch
bg="red"
value="svelte"
label="Testing if its also broken when the label is long. Yep, seems a small."
/>
</Box>
);
}
2 changes: 1 addition & 1 deletion packages/@mantine/core/src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const Switch = factory<SwitchFactory>((_props, ref) => {

<Box
aria-hidden="true"
mod={{ error, 'label-position': labelPosition }}
mod={{ error, 'label-position': labelPosition, 'without-labels': !onLabel && !offLabel }}
{...getStyles('track')}
>
<Box component="span" mod="reduce-motion" {...getStyles('thumb')}>
Expand Down

0 comments on commit 4a17e88

Please sign in to comment.