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

🚀 feat: add arial label to input component #856

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ exports[`<Dropdown /> should match snapshot 1`] = `
aria-labelledby="downshift-0-label"
autocomplete="off"
class="c4 c5"
data-testid="input"
id="downshift-0-input"
label="Find an activity to love"
readonly=""
Expand Down Expand Up @@ -551,6 +552,7 @@ exports[`<Dropdown /> should match snapshot when disabled 1`] = `
aria-labelledby="downshift-1-label"
autocomplete="off"
class="c3 c4"
data-testid="input"
disabled=""
id="downshift-1-input"
label="Find an activity to love"
Expand Down Expand Up @@ -850,6 +852,7 @@ exports[`<Dropdown /> should match snapshot when full 1`] = `
aria-labelledby="downshift-2-label"
autocomplete="off"
class="c4 c5"
data-testid="input"
id="downshift-2-input"
label="Find an activity to love"
readonly=""
Expand Down Expand Up @@ -1168,6 +1171,7 @@ exports[`<Dropdown /> should match snapshot when has a selected value 1`] = `
aria-labelledby="downshift-3-label"
autocomplete="off"
class="c3 c4"
data-testid="input"
disabled=""
id="downshift-3-input"
label="Find an activity to love"
Expand Down Expand Up @@ -1535,6 +1539,7 @@ exports[`<Dropdown /> should match snapshot with error 1`] = `
aria-labelledby="downshift-4-label"
autocomplete="off"
class="c4 c5"
data-testid="input"
id="downshift-4-input"
label="Find an activity to love"
readonly=""
Expand Down
10 changes: 8 additions & 2 deletions packages/yoga/src/Input/web/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const Input = React.forwardRef(
full,
helper,
label,
ariaLabel,
maxLength,
readOnly,
style,
Expand Down Expand Up @@ -135,14 +136,16 @@ const Input = React.forwardRef(
const labelA11yId = includeAriaAttributes && a11yId && `${a11yId}-label`;
let a11yFieldProps;

const labelAria = ariaLabel || label;

if (includeAriaAttributes) {
a11yFieldProps = a11yId
? {
...(hasHelper && { 'aria-describedby': helperA11yId }),
...(label && { 'aria-labelledby': labelA11yId }),
}
: {
...(label && { 'aria-label': label }),
...(labelAria && { 'aria-label': labelAria }),
};
a11yFieldProps['aria-invalid'] = !!error;
} else {
Expand Down Expand Up @@ -186,6 +189,7 @@ const Input = React.forwardRef(
maxLength,
}}
ref={inputRef}
data-testid="input"
value={value}
onChange={onChange}
{...a11yFieldProps}
Expand Down Expand Up @@ -259,6 +263,7 @@ Input.propTypes = {
/** a helper text to be displayed below field */
helper: string,
label: string,
ariaLabel: string,
/** maximum length (number of characters) of value */
maxLength: number,
readOnly: bool,
Expand Down Expand Up @@ -290,7 +295,8 @@ Input.defaultProps = {
error: undefined,
full: false,
helper: undefined,
label: 'Label',
label: undefined,
ariaLabel: undefined,
maxLength: undefined,
readOnly: false,
style: undefined,
Expand Down
31 changes: 30 additions & 1 deletion packages/yoga/src/Input/web/Input.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('<Input />', () => {
it('should test if clean button is present', () => {
const { rerender } = render(
<ThemeProvider>
<Input label="Input" />
<Input label="Input" ariaLabel="valor aria label" />
</ThemeProvider>,
);

Expand All @@ -206,5 +206,34 @@ describe('<Input />', () => {

expect(screen.queryByRole('button')).not.toBeNull();
});

it('should have aria-label', () => {
const value = 'aria label value';
const { getByTestId } = render(
<ThemeProvider>
<Input label="Input" value="foo" ariaLabel={value} />
</ThemeProvider>,
);

const inputElement = getByTestId('input');

expect(inputElement).toBeInTheDocument();

expect(inputElement).toHaveAttribute('aria-label', value);
});
it('should have label value', () => {
const value = 'label value';
const { getByTestId } = render(
<ThemeProvider>
<Input label={value} value="foo" />
</ThemeProvider>,
);

const inputElement = getByTestId('input');

expect(inputElement).toBeInTheDocument();

expect(inputElement).toHaveAttribute('aria-label', value);
});
});
});
43 changes: 2 additions & 41 deletions packages/yoga/src/Input/web/__snapshots__/Email.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,6 @@ exports[`<Input.Email /> Snapshots should match with default input 1`] = `
border-color: #231B22;
}

.c4 {
position: relative;
padding: 0;
max-width: 0;
width: auto;
height: 0;
visibility: hidden;
-webkit-transition-property: max-width,padding;
transition-property: max-width,padding;
font-family: Rubik;
font-size: 12px;
font-weight: 400;
line-height: 16px;
-webkit-letter-spacing: normal;
-moz-letter-spacing: normal;
-ms-letter-spacing: normal;
letter-spacing: normal;
-webkit-transition-duration: 100ms;
transition-duration: 100ms;
}

.c5 {
padding-left: 4px;
padding-right: 4px;
}

.c3 {
-webkit-letter-spacing: normal;
-moz-letter-spacing: normal;
Expand Down Expand Up @@ -186,31 +160,18 @@ exports[`<Input.Email /> Snapshots should match with default input 1`] = `
>
<fieldset
class="c1"
label="Label"
value=""
>
<input
aria-invalid="false"
aria-label="Label"
class="c2"
label="Label"
data-testid="input"
type="email"
value=""
/>
<label
class="c3"
>
Label
</label>
<legend
class="c4"
>
<span
class="c5"
>
Label
</span>
</legend>
/>
</fieldset>
</div>
</div>
Expand Down
Loading
Loading