Skip to content

Commit

Permalink
fix: fix the color contrast of form controls in disabled state (#3809)
Browse files Browse the repository at this point in the history
* fix: fix the color contrast of form controls in disabled state

* test: updated tests

* test: updated tests
  • Loading branch information
simonguo committed May 17, 2024
1 parent 157a2bf commit 211ce5f
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 184 deletions.
16 changes: 14 additions & 2 deletions docs/pages/components/form/fragments/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
MultiCascader,
Rate,
Uploader,
Panel
Panel,
Toggle
} from 'rsuite';

import { mockTreeData } from './mock';
Expand All @@ -46,7 +47,8 @@ const defaultFormValue = {
inputPicker: '',
cascader: '',
multiCascader: [],
rate: 0
rate: 0,
enable: false
};

const initFormValue = {
Expand Down Expand Up @@ -183,6 +185,16 @@ const App = () => {
<Form.ControlLabel>Uploader:</Form.ControlLabel>
<Form.Control name="uploader" accepter={Uploader} action="#" />
</Form.Group>

<Form.Group controlId="toggle">
<Form.ControlLabel>Toggle:</Form.ControlLabel>
<Form.Control
name="enable"
accepter={Toggle}
unCheckedChildren="Disabled"
checkedChildren="Enabled"
/>
</Form.Group>
</Form>
</Panel>
);
Expand Down
73 changes: 29 additions & 44 deletions src/AutoComplete/test/AutoCompleteStylesSpec.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import AutoComplete from '../index';
import { getStyle, toRGB, inChrome } from '@test/utils';

import { toRGB, inChrome } from '@test/utils';
import '../styles/index.less';
import { PickerHandle } from '../../internals/Picker';

describe('AutoComplete styles', () => {
it('Input should render the correct styles', () => {
const instanceRef = React.createRef<PickerHandle>();
render(<AutoComplete ref={instanceRef} data={[]} />);
const dom = ((instanceRef.current as PickerHandle).root as HTMLElement).querySelector(
'input'
) as HTMLInputElement;
assert.equal(getStyle(dom, 'backgroundColor'), toRGB('#fff'), 'AutoComplete background-color');
// @description Can't get border-radius value in other browser except chrome
inChrome &&
assert.equal(getStyle(dom, 'border'), `1px solid ${toRGB('#e5e5ea')}`, 'AutoComplete border');
assert.equal(getStyle(dom, 'color'), toRGB('#575757'), 'AutoComplete font-color');
inChrome && assert.equal(getStyle(dom, 'borderRadius'), '6px', 'AutoComplete border-radius');
it('Should render the correct styles', () => {
render(<AutoComplete data={[]} />);

expect(screen.getByRole('combobox')).to.have.style('background-color', toRGB('#fff'));
expect(screen.getByRole('combobox')).to.have.style('color', toRGB('#575757'));
expect(screen.getByRole('combobox')).to.have.style('border', `1px solid ${toRGB('#e5e5ea')}`);
expect(screen.getByRole('combobox')).to.have.style('border-radius', '6px');
});

it('Should the correct styles when set `open` and `defaultValue`', () => {
const instanceRef = React.createRef<PickerHandle>();
render(<AutoComplete ref={instanceRef} data={['a', 'b', 'ab']} open defaultValue="a" />);
const dom = ((instanceRef.current as PickerHandle).root as HTMLElement).querySelector(
'input'
) as HTMLInputElement;
const unFocusItemDom = document.querySelector(
'.rs-auto-complete-item:not(.rs-auto-complete-item-focus)'
) as HTMLElement;

assert.equal(getStyle(dom, 'color'), toRGB('#575757'), 'AutoComplete focus item font-color');
assert.equal(
getStyle(unFocusItemDom, 'backgroundColor'),
toRGB('#0000'),
'AutoComplete unFocus item background-color'
);
it('Should render the correct styles when set `open`', () => {
render(<AutoComplete data={['a', 'b', 'ab']} open defaultValue="a" />);

const options = screen.getAllByRole('option');

// Focused option
const focusedBgColor = inChrome
? 'color(srgb 0.8 0.913725 1 / 0.5)'
: 'rgba(204, 233, 255, 0.5)';
expect(options[0].firstChild).to.have.style('color', toRGB('#1675e0'));
expect(options[0].firstChild).to.have.style('background-color', focusedBgColor);

// Unfocused option
expect(options[1].firstChild).to.have.style('color', toRGB('#575757'));
expect(options[1].firstChild).to.have.style('background-color', toRGB('#0000'));
});

it('Disabled should render the correct styles', () => {
const instanceRef = React.createRef<PickerHandle>();
render(<AutoComplete ref={instanceRef} data={[]} disabled />);
const dom = ((instanceRef.current as PickerHandle).root as HTMLElement).querySelector(
'input'
) as HTMLInputElement;
assert.equal(
getStyle(dom, 'backgroundColor'),
toRGB('#f7f7fa'),
'Disabled autoComplete background-color'
);
assert.equal(getStyle(dom, 'color'), toRGB('#c5c6c7'), 'Disabled autoComplete color');
it('Should render the correct styles when set `disabled`', () => {
render(<AutoComplete data={[]} disabled />);

expect(screen.getByRole('combobox')).to.have.style('background-color', toRGB('#f7f7fa'));
expect(screen.getByRole('combobox')).to.have.style('color', toRGB('#8e8e93'));
});
});
2 changes: 1 addition & 1 deletion src/Button/styles/mixin.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@rules();

.high-contrast-mode({
opacity: 0.5;
border-color: var(--rs-btn-default-disabled-boreder-color);
});
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Checkbox/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@

.rs-checkbox-disabled.rs-checkbox-checked &,
.rs-checkbox-disabled.rs-checkbox-indeterminate & {
opacity: 0.3;

.high-contrast-mode({
opacity: 0.5;
});
opacity: 0.5;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ const DatePicker: RsRefForwardingComponent<'div', DatePickerProps> = React.forwa
{...getRestProps(rest, usedClassNamePropKeys)}
inside
size={size}
disabled={disabled}
onClick={handleClick}
>
<PickerLabel className={prefix`label`} id={`${id}-label`}>
Expand Down
1 change: 1 addition & 0 deletions src/DateRangePicker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ const DateRangePicker = React.forwardRef((props: DateRangePickerProps, ref) => {
...calendarOnlyProps
])}
inside
disabled={disabled}
size={size}
>
<PickerLabel className={prefix`label`} id={`${id}-label`}>
Expand Down
2 changes: 1 addition & 1 deletion src/InputGroup/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
}
}

.rs-input-group-disabled {
.rs-input-group.rs-input-group-disabled {
background-color: var(--rs-input-disabled-bg);
color: var(--rs-text-disabled);
cursor: not-allowed;
Expand Down
3 changes: 1 addition & 2 deletions src/Nav/test/NavItemStylesSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import Nav from '../index';
import { toRGB, getDefaultPalette } from '@test/utils';

import '../styles/index.less';

const { H700 } = getDefaultPalette();
Expand Down Expand Up @@ -40,7 +39,7 @@ describe('NavItem styles', () => {

const navItemDisabled = screen.getByText('Disabled nav item');

expect(navItemDisabled).to.have.style('color', toRGB('#c5c6c7'));
expect(navItemDisabled).to.have.style('color', toRGB('#8e8e93'));
expect(navItemDisabled).to.have.style('cursor', 'not-allowed');
});
});
6 changes: 1 addition & 5 deletions src/Radio/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@
}

.rs-radio.rs-radio-disabled.rs-radio-checked & {
opacity: 0.3;

.high-contrast-mode({
opacity: 0.5;
});
opacity: 0.5;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rate/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

&-disabled {
opacity: 0.3;
opacity: 0.5;
outline: none;
}

Expand Down
Loading

0 comments on commit 211ce5f

Please sign in to comment.