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

patch(5.10-stable): pr6373 #6411

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
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@ describe('CustomSelect', () => {
});

it('native select is reachable via nativeSelectTestId', () => {
// Это позволяет скринридеру зачитывать placeholder, если опция не выбрана.
render(
<CustomSelect
nativeSelectTestId="nativeSelectTestId"
Expand All @@ -1078,4 +1077,27 @@ describe('CustomSelect', () => {
const nativeSelect = screen.getByTestId<HTMLSelectElement>('nativeSelectTestId');
expect(nativeSelect.value).toBe('1');
});

it('passes required prop to native select, not input', () => {
render(
<CustomSelect
nativeSelectTestId="nativeSelectTestId"
data-testid="inputTestId"
options={[
{ value: 0, label: 'Mike' },
{ value: 1, label: 'Josh' },
]}
placeholder="Не выбрано"
allowClearButton
defaultValue={1}
required
/>,
);

const nativeSelect = screen.getByTestId<HTMLSelectElement>('nativeSelectTestId');
expect(nativeSelect.required).toBeTruthy();

const input = screen.getByTestId<HTMLInputElement>('inputTestId');
expect(input.required).toBeFalsy();
});
});
2 changes: 2 additions & 0 deletions packages/vkui/src/components/CustomSelect/CustomSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac
clearButtonTestId,
nativeSelectTestId,
defaultValue,
required,
...restProps
} = props;

Expand Down Expand Up @@ -890,6 +891,7 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac
aria-hidden
className={styles['CustomSelect__control']}
data-testid={nativeSelectTestId}
required={required}
>
{allowClearButton && <option key="" value="" />}
{optionsProp.map((item) => (
Expand Down
Loading