1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00

chore: fix weird button styling (#10113)

This commit is contained in:
Thomas Heartman 2025-06-11 14:07:24 +02:00 committed by GitHub
parent ddb5ffb955
commit 0e818c54ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 62 additions and 52 deletions

View File

@ -41,7 +41,7 @@ test('Enabled new token button when limits, version and permission allow for it'
await waitFor(async () => { await waitFor(async () => {
const button = await screen.findByText('Create token'); const button = await screen.findByText('Create token');
expect(button).not.toBeDisabled(); expect(button).not.toHaveAttribute('aria-disabled');
}); });
}); });
@ -54,5 +54,5 @@ test('Token limit reached', async () => {
await screen.findByText('You have reached the limit for API tokens'); await screen.findByText('You have reached the limit for API tokens');
const button = await screen.findByText('Create token'); const button = await screen.findByText('Create token');
expect(button).toBeDisabled(); expect(button).toHaveAttribute('aria-disabled', 'true');
}); });

View File

@ -57,6 +57,6 @@ test('should not allow you to create API tokens when you have reached the limit'
await waitFor(async () => { await waitFor(async () => {
const button = await screen.findByRole('button'); const button = await screen.findByRole('button');
expect(button).toBeDisabled(); expect(button).toHaveAttribute('aria-disabled', 'true');
}); });
}); });

View File

@ -15,6 +15,9 @@ import {
const StyledButton = styled(Button)({ const StyledButton = styled(Button)({
justifySelf: 'start', justifySelf: 'start',
alignSelf: 'start', alignSelf: 'start',
'&.Mui-disabled': {
pointerEvents: 'auto',
},
}); });
export interface IPermissionButtonProps extends Omit<ButtonProps, 'title'> { export interface IPermissionButtonProps extends Omit<ButtonProps, 'title'> {
@ -96,10 +99,12 @@ const BasePermissionButton = React.forwardRef<
environmentId, environmentId,
tooltipProps, tooltipProps,
hideLockIcon, hideLockIcon,
className,
...rest ...rest
}, },
ref, ref,
) => { ) => {
const disableButton = disabled || !access;
const id = useId(); const id = useId();
const endIcon = getEndIcon(access, rest.endIcon, hideLockIcon); const endIcon = getEndIcon(access, rest.endIcon, hideLockIcon);
@ -109,20 +114,21 @@ const BasePermissionButton = React.forwardRef<
title={formatAccessText(access, tooltipProps?.title)} title={formatAccessText(access, tooltipProps?.title)}
arrow arrow
> >
<span>
<StyledButton <StyledButton
ref={ref} ref={ref}
onClick={onClick} onClick={disableButton ? undefined : onClick}
disabled={disabled || !access} aria-disabled={disableButton || undefined}
aria-labelledby={id} aria-labelledby={id}
variant={variant} variant={variant}
color={color} color={color}
className={
disableButton ? `${className} Mui-disabled` : className
}
{...rest} {...rest}
endIcon={endIcon} endIcon={endIcon}
> >
{children} {children}
</StyledButton> </StyledButton>
</span>
</TooltipResolver> </TooltipResolver>
); );
}, },

View File

@ -31,7 +31,7 @@ test('show limit reached info', async () => {
const createButton = await screen.findByText('Create environment', { const createButton = await screen.findByText('Create environment', {
selector: 'button', selector: 'button',
}); });
expect(createButton).toBeDisabled(); expect(createButton).toHaveAttribute('aria-disabled', 'true');
}); });
test('show approaching limit info', async () => { test('show approaching limit info', async () => {

View File

@ -61,6 +61,6 @@ describe('FeatureOverviewEnvironment', () => {
); );
const button = await screen.findByText('Add strategy'); const button = await screen.findByText('Add strategy');
expect(button).toBeDisabled(); expect(button).toHaveAttribute('aria-disabled', 'true');
}); });
}); });

View File

@ -29,7 +29,10 @@ describe('FeatureTypeForm', () => {
); );
expect(screen.getByLabelText('Expected lifetime')).toBeDisabled(); expect(screen.getByLabelText('Expected lifetime')).toBeDisabled();
expect(screen.getByLabelText("doesn't expire")).toBeDisabled(); expect(screen.getByLabelText("doesn't expire")).toBeDisabled();
expect(screen.getByText('Save feature flag type')).toBeDisabled(); expect(screen.getByText('Save feature flag type')).toHaveAttribute(
'aria-disabled',
'true',
);
}); });
it('should check "doesn\'t expire" when lifetime is 0', () => { it('should check "doesn\'t expire" when lifetime is 0', () => {
@ -87,6 +90,9 @@ describe('FeatureTypeForm', () => {
loading={false} loading={false}
/>, />,
); );
expect(screen.getByText('Save feature flag type')).toBeDisabled(); expect(screen.getByText('Save feature flag type')).toHaveAttribute(
'aria-disabled',
'true',
);
}); });
}); });

View File

@ -46,5 +46,5 @@ test('Project limit reached', async () => {
const button = await screen.findByRole('button', { const button = await screen.findByRole('button', {
name: 'Create project', name: 'Create project',
}); });
expect(button).toBeDisabled(); expect(button).toHaveAttribute('aria-disabled', 'true');
}); });

View File

@ -148,5 +148,5 @@ test('Show validation errors', async () => {
await screen.findByText('itemF'); await screen.findByText('itemF');
const importButton = screen.getByText('Import configuration'); const importButton = screen.getByText('Import configuration');
expect(importButton).toBeDisabled(); expect(importButton).toHaveAttribute('aria-disabled', 'true');
}); });

View File

@ -26,10 +26,10 @@ test('Enabled new project button when version and permission allow for it and li
}); });
const button = await screen.findByText('New project'); const button = await screen.findByText('New project');
expect(button).toBeDisabled(); expect(button).toHaveAttribute('aria-disabled', 'true');
await waitFor(async () => { await waitFor(async () => {
const button = await screen.findByText('New project'); const button = await screen.findByText('New project');
expect(button).not.toBeDisabled(); expect(button).not.toHaveAttribute('aria-disabled', 'true');
}); });
}); });

View File

@ -73,10 +73,9 @@ exports[`renders an empty list correctly 1`] = `
<hr <hr
className="MuiDivider-root MuiDivider-middle MuiDivider-vertical css-1cqsk4j-MuiDivider-root" className="MuiDivider-root MuiDivider-middle MuiDivider-vertical css-1cqsk4j-MuiDivider-root"
/> />
<span>
<button <button
aria-labelledby="useId-0" aria-labelledby="useId-0"
className="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium css-1ind840-MuiButtonBase-root-MuiButton-root" className="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium css-9qsbea-MuiButtonBase-root-MuiButton-root"
disabled={false} disabled={false}
onBlur={[Function]} onBlur={[Function]}
onClick={[Function]} onClick={[Function]}
@ -99,7 +98,6 @@ exports[`renders an empty list correctly 1`] = `
className="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root" className="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/> />
</button> </button>
</span>
</div> </div>
</div> </div>
</div> </div>