Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] Button: Button is disabled when inside fieldset disabled #2440

Merged
merged 4 commits into from Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mantine-core/src/ActionIcon/ActionIcon.story.tsx
Expand Up @@ -111,6 +111,14 @@ export function States() {
);
}

export function StatesInsideFieldsetDisabled() {
return (
<fieldset disabled>
<States />
</fieldset>
);
}

export function ColorsIndex() {
return (
<div style={{ padding: 40 }}>
Expand Down
3 changes: 2 additions & 1 deletion src/mantine-core/src/ActionIcon/ActionIcon.styles.ts
Expand Up @@ -84,7 +84,7 @@ export default createStyles(

'&:active': theme.activeStyles,

'&[data-disabled]': {
'&:disabled, &[data-disabled]': {
color: theme.colors.gray[theme.colorScheme === 'dark' ? 6 : 4],
cursor: 'not-allowed',
backgroundColor:
Expand All @@ -96,6 +96,7 @@ export default createStyles(
? undefined
: theme.fn.themeColor('gray', theme.colorScheme === 'dark' ? 8 : 1),
backgroundImage: 'none',
pointerEvents: 'none',

'&:active': {
transform: 'none',
Expand Down
9 changes: 9 additions & 0 deletions src/mantine-core/src/ActionIcon/ActionIcon.test.tsx
Expand Up @@ -64,4 +64,13 @@ describe('@mantine/core/ActionIcon', () => {
expect(loading.querySelectorAll('.test-icon')).toHaveLength(0);
expect(loading.querySelectorAll('svg')).toHaveLength(1);
});

it('is disabled when inside fieldset disabled', () => {
render(
<fieldset disabled>
<ActionIcon>$</ActionIcon>
</fieldset>
);
expect(screen.getByRole('button')).toBeDisabled();
});
});
10 changes: 10 additions & 0 deletions src/mantine-core/src/Button/Button.story.tsx
Expand Up @@ -128,6 +128,16 @@ export function States() {
);
}

/**
* All buttons should be disabled
*/
export function StatesInFieldsetDisabled() {
return (
<fieldset disabled>
<States />
</fieldset>
);
}
export function CustomComponent() {
return (
<div style={{ padding: 40 }}>
Expand Down
3 changes: 2 additions & 1 deletion src/mantine-core/src/Button/Button.styles.ts
Expand Up @@ -135,12 +135,13 @@ export default createStyles(

'&:active': theme.activeStyles,

'&[data-disabled]': {
'&:disabled, &[data-disabled]': {
borderColor: 'transparent',
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[2],
color: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[5],
cursor: 'not-allowed',
backgroundImage: 'none',
pointerEvents: 'none',

'&:active': {
transform: 'none',
Expand Down
9 changes: 9 additions & 0 deletions src/mantine-core/src/Button/Button.test.tsx
Expand Up @@ -52,4 +52,13 @@ describe('@mantine/core/Button', () => {
it('exposes ButtonGroup as static component', () => {
expect(Button.Group).toBe(ButtonGroup);
});

it('is disabled when inside fieldset disabled', () => {
render(
<fieldset disabled>
<Button type="submit" />
</fieldset>
);
expect(screen.getByRole('button')).toBeDisabled();
});
});