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

fix(Select): show invalid state without passing error message #1554

Merged
merged 1 commit into from
Apr 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
});
const errorMessageId = useUniqId();

const isErrorStateVisible = validationState === 'invalid';
const isErrorMsgVisible =
validationState === 'invalid' && Boolean(errorMessage) && errorPlacement === 'outside';
isErrorStateVisible && Boolean(errorMessage) && errorPlacement === 'outside';
const isErrorIconVisible =
validationState === 'invalid' && Boolean(errorMessage) && errorPlacement === 'inside';
const isErrorStateVisible = isErrorMsgVisible || isErrorIconVisible;
isErrorStateVisible && Boolean(errorMessage) && errorPlacement === 'inside';

const handleOptionClick = React.useCallback(
(option?: FlattenOption) => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/Select/__tests__/Select.error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import {render, screen} from '../../../../test-utils/utils';
import {CONTROL_ERROR_MESSAGE_QA} from '../../controls/utils';
import {Select} from '../Select';

import {SELECT_CONTROL_BUTTON_ERROR_CLASS, TEST_QA, setup} from './utils';

describe('Select error', () => {
test('render error appearance with invalid state and without errorMessage', () => {
const {getByTestId} = setup({validationState: 'invalid'});
const selectControl = getByTestId(TEST_QA);

expect(selectControl).toHaveClass(SELECT_CONTROL_BUTTON_ERROR_CLASS);
});
test('render error message with error prop (if it is not an empty string)', () => {
render(<Select error="Some Error" />);

Expand Down
1 change: 1 addition & 0 deletions src/components/Select/__tests__/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const OptionsListType = {
export const TEST_QA = 'select-test-qa';
export const SELECT_CONTROL_OPEN_CLASS = selectControlBlock({open: true});
export const SELECT_CONTROL_BUTTON_OPEN_CLASS = selectControlButtonBlock({open: true});
export const SELECT_CONTROL_BUTTON_ERROR_CLASS = selectControlButtonBlock({error: true});
export const SELECT_LIST_VIRTUALIZED_CLASS = selectListBlock({virtualized: true});
export const DEFAULT_OPTIONS = generateOptions([
['js', 'JavaScript'],
Expand Down
Loading