Skip to content

Commit

Permalink
Making aria-label required for select component (#611)
Browse files Browse the repository at this point in the history
* made aria-label required for select component

* omiting aria-label from the HTMLAttributes inheritance
  • Loading branch information
bearni95 authored Jul 20, 2023
1 parent 0ccaa3b commit 662be9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const Dynamic: Story = {
const [value, setValue] = useState<string>('1');
return (
<Select
ariaLabel={'select'}
icon={SystemIcon[icon]}
onChange={(e) => {
console.log('clicked on', e.target.value);
Expand Down
10 changes: 5 additions & 5 deletions packages/libs/react-ui/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('Select', () => {
it('renders without errors', () => {
const { getByTestId } = render(
<Select value="1" onChange={() => {}}>
<Select value="1" onChange={() => {}} ariaLabel="select">
<Option value="1">Option 1</Option>
<Option value="2">Option 2</Option>
</Select>,
Expand All @@ -18,7 +18,7 @@ describe('Select', () => {

it('renders the provided children options', () => {
const { getByTestId } = render(
<Select value="1" onChange={() => {}}>
<Select value="1" onChange={() => {}} ariaLabel="select">
<Option value="1">Option 1</Option>
<Option value="2">Option 2</Option>
</Select>,
Expand All @@ -37,7 +37,7 @@ describe('Select', () => {
it('invokes the onChange event handler when an option is selected', () => {
const handleChange = jest.fn();
const { getByTestId } = render(
<Select value="1" onChange={handleChange}>
<Select value="1" onChange={handleChange} ariaLabel="select">
<Option value="1">Option 1</Option>
<Option value="2">Option 2</Option>
</Select>,
Expand All @@ -54,7 +54,7 @@ describe('Select', () => {

it('disables the select element when disabled prop is true', () => {
const { getByTestId } = render(
<Select value="1" onChange={() => {}} disabled>
<Select value="1" onChange={() => {}} disabled ariaLabel="select">
<Option value="1">Option 1</Option>
<Option value="2">Option 2</Option>
</Select>,
Expand All @@ -71,7 +71,7 @@ describe('Select', () => {
it('renders an icon when the "icon" prop is provided', () => {
const IconMock = jest.fn(() => <span className="icon">User</span>);
const { getByTestId, getByText } = render(
<Select value="1" onChange={() => {}} icon={IconMock}>
<Select value="1" onChange={() => {}} icon={IconMock} ariaLabel="select">
<Option value="1">Option 1</Option>
<Option value="2">Option 2</Option>
</Select>,
Expand Down
8 changes: 7 additions & 1 deletion packages/libs/react-ui/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import classNames from 'classnames';
import React, { FC, forwardRef } from 'react';

export interface ISelectProps
extends Omit<React.HTMLAttributes<HTMLSelectElement>, 'as' | 'className'> {
extends Omit<
React.HTMLAttributes<HTMLSelectElement>,
'aria-label' | 'as' | 'className'
> {
children: React.ReactNode;
icon?: (typeof SystemIcon)[keyof typeof SystemIcon];
disabled?: boolean;
value: string[] | string | number;
onChange: React.ChangeEventHandler<HTMLSelectElement>;
ref?: React.ForwardedRef<HTMLSelectElement>;
ariaLabel: string;
}

export const Select: FC<ISelectProps> = forwardRef<
Expand All @@ -30,6 +34,7 @@ export const Select: FC<ISelectProps> = forwardRef<
icon: Icon,
disabled = false,
children,
ariaLabel,
...rest
},
ref,
Expand All @@ -49,6 +54,7 @@ export const Select: FC<ISelectProps> = forwardRef<
</span>
)}
<select
aria-label={ariaLabel}
ref={ref}
className={selectClass}
disabled={Boolean(disabled)}
Expand Down

1 comment on commit 662be9b

@vercel
Copy link

@vercel vercel bot commented on 662be9b Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-ui – ./packages/libs/react-ui

react-ui-git-main-kadena-js.vercel.app
react-ui-kadena-js.vercel.app
react-ui.kadena.io
react-ui-delta.vercel.app

Please sign in to comment.