Skip to content

Commit

Permalink
[@mantine/core] Fix incorrect selectors used to style Radio, Checkbox…
Browse files Browse the repository at this point in the history
… and Switch components
  • Loading branch information
rtivital committed Oct 3, 2022
1 parent ec1edd0 commit 129d6b5
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/mantine-core/src/Button/Button.test.tsx
Expand Up @@ -45,7 +45,6 @@ describe('@mantine/core/Button', () => {

it('sets data-loading attribute based on loading prop', () => {
render(<Button loading />);
expect(screen.getByRole('button')).toBeDisabled();
expect(screen.getByRole('button')).toHaveAttribute('data-loading');
});

Expand Down
10 changes: 7 additions & 3 deletions src/mantine-core/src/Checkbox/Checkbox.styles.ts
Expand Up @@ -47,10 +47,16 @@ export default createStyles(
return {
description: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

error: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

label: {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

icon: {
Expand Down Expand Up @@ -98,9 +104,7 @@ export default createStyles(
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
cursor: theme.cursorType,
order: labelPosition === 'left' ? 1 : 2,
'& *': {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

'& label[data-disabled]': {
color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
},
Expand Down
7 changes: 6 additions & 1 deletion src/mantine-core/src/Checkbox/Checkbox.tsx
Expand Up @@ -147,7 +147,12 @@ export const Checkbox: CheckboxComponent = forwardRef<HTMLInputElement, Checkbox

<div className={classes.labelWrapper}>
{label && (
<label data-disabled={disabled || undefined} htmlFor={uuid} data-testid="label">
<label
className={classes.label}
data-disabled={disabled || undefined}
htmlFor={uuid}
data-testid="label"
>
{label}
</label>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/mantine-core/src/Input/InputWrapper/InputWrapper.tsx
Expand Up @@ -136,7 +136,7 @@ export const InputWrapper = forwardRef<HTMLDivElement, InputWrapperProps>((props
key="description"
{...descriptionProps}
{...sharedProps}
size={descriptionProps.size || sharedProps.size}
size={descriptionProps?.size || sharedProps.size}
>
{description}
</InputDescription>
Expand All @@ -148,7 +148,7 @@ export const InputWrapper = forwardRef<HTMLDivElement, InputWrapperProps>((props
<InputError
{...errorProps}
{...sharedProps}
size={errorProps.size || sharedProps.size}
size={errorProps?.size || sharedProps.size}
key="error"
>
{error}
Expand Down
9 changes: 6 additions & 3 deletions src/mantine-core/src/Radio/Radio.styles.ts
Expand Up @@ -34,10 +34,16 @@ export default createStyles(

description: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

error: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

label: {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

body: {
Expand Down Expand Up @@ -118,9 +124,6 @@ export default createStyles(
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
cursor: theme.cursorType,
order: labelPosition === 'left' ? 1 : 2,
'& *': {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

'& label[data-disabled]': {
color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
Expand Down
2 changes: 1 addition & 1 deletion src/mantine-core/src/Radio/Radio.tsx
Expand Up @@ -126,7 +126,7 @@ export const Radio: RadioComponent = forwardRef<HTMLInputElement, RadioProps>((p

<div className={classes.labelWrapper}>
{label && (
<label data-disabled={disabled || undefined} htmlFor={uuid}>
<label className={classes.label} data-disabled={disabled || undefined} htmlFor={uuid}>
{label}
</label>
)}
Expand Down
14 changes: 7 additions & 7 deletions src/mantine-core/src/Switch/Switch.styles.ts
Expand Up @@ -58,16 +58,20 @@ export default createStyles(
const errorColor = theme.fn.variant({ variant: 'filled', color: 'red' }).background;

return {
root: {},

description: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

error: {
marginTop: `calc(${theme.spacing.xs}px / 2)`,
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

root: {
display: 'block',
label: {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

body: {
Expand Down Expand Up @@ -114,8 +118,6 @@ export default createStyles(
fontSize: theme.fn.size({ size, sizes: labelFontSizes }),
fontWeight: 600,
order: labelPosition === 'left' ? 2 : 1,

// for disabling text selection on double click
userSelect: 'none',
MozUserSelect: 'none',
WebkitUserSelect: 'none',
Expand Down Expand Up @@ -182,9 +184,7 @@ export default createStyles(
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
cursor: theme.cursorType,
order: labelPosition === 'left' ? 1 : 2,
'& *': {
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm,
},

'& label[data-disabled]': {
color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
},
Expand Down
7 changes: 6 additions & 1 deletion src/mantine-core/src/Switch/Switch.tsx
Expand Up @@ -147,7 +147,12 @@ export const Switch: SwitchComponent = forwardRef<HTMLInputElement, SwitchProps>

<div className={classes.labelWrapper}>
{label && (
<label data-disabled={rest.disabled || undefined} htmlFor={uuid} data-testid="label">
<label
className={classes.label}
data-disabled={rest.disabled || undefined}
htmlFor={uuid}
data-testid="label"
>
{label}
</label>
)}
Expand Down
Expand Up @@ -9,4 +9,5 @@ export const Checkbox: Record<CheckboxStylesNames, string> = {
icon: 'Checked or indeterminate state icon',
error: 'Error message',
description: 'Description',
label: 'Label',
};
1 change: 1 addition & 0 deletions src/mantine-styles-api/src/styles-api/Radio.styles-api.ts
Expand Up @@ -12,4 +12,5 @@ export const Radio: Record<RadioStylesNames, string> = {
icon: 'Radio button icon',
error: 'Error message',
description: 'Description',
label: 'Label',
};
1 change: 1 addition & 0 deletions src/mantine-styles-api/src/styles-api/Switch.styles-api.ts
Expand Up @@ -10,4 +10,5 @@ export const Switch: Record<SwitchStylesNames, string> = {
trackLabel: 'onLabel and offLabel',
error: 'Error message',
description: 'Description',
label: 'Label',
};

0 comments on commit 129d6b5

Please sign in to comment.