Skip to content

Commit

Permalink
Fix error span id & add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Aug 16, 2023
1 parent 60adfac commit a255f32
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/web-components/assets/arrow-both.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/web-components/assets/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/web-components/assets/green-check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/web-components/assets/icon-dot-gov.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/web-components/assets/icon-https.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/web-components/assets/minus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/web-components/assets/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/web-components/assets/sort-arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/web-components/assets/sort-arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/web-components/assets/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/web-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ export namespace Components {
}
interface VaTextarea {
/**
* Whether the component should show a character count message. Has no effect without uswds and maxlength being set.
* Whether the component should show a character count message. Has no effect without uswds and maxlength being set.
*/
"charcount"?: boolean;
/**
Expand Down Expand Up @@ -3018,7 +3018,7 @@ declare namespace LocalJSX {
}
interface VaTextarea {
/**
* Whether the component should show a character count message. Has no effect without uswds and maxlength being set.
* Whether the component should show a character count message. Has no effect without uswds and maxlength being set.
*/
"charcount"?: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('va-text-input', () => {
const input = await page.find('va-text-input >>> input');
expect(error.innerText).toContain('This is a mistake');
expect(input.getAttribute('aria-invalid')).toEqual('true');
expect(input.getAttribute('aria-describedby')).toContain('input-error-message');
});

it('sets aria-invalid based on invalid prop', async () => {
Expand Down Expand Up @@ -385,6 +386,7 @@ describe('va-text-input', () => {
const input = await page.find('va-text-input >>> input');
expect(error.innerText).toContain('This is a mistake');
expect(input.getAttribute('aria-invalid')).toEqual('true');
expect(input.getAttribute('aria-describedby')).toContain('input-error-message');
});

it('uswds sets aria-invalid based on invalid prop', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('va-textarea', () => {
<label for="textarea">
Describe your situation
</label>
<span id="error-message" role="alert"></span>
<span id="input-error-message" role="alert"></span>
<textarea id="textarea" part="textarea" aria-invalid="false"></textarea>
</mock:shadow-root>
</va-textarea>
Expand All @@ -27,7 +27,7 @@ describe('va-textarea', () => {
await page.setContent('<va-textarea error="This is a mistake" />');

// Render the error message text
const error = await page.find('va-textarea >>> span#error-message');
const error = await page.find('va-textarea >>> span#input-error-message');
const textarea = await page.find('va-textarea >>> textarea');
expect(error.innerText).toContain('This is a mistake');
expect(textarea.getAttribute('aria-invalid')).toEqual('true');
Expand All @@ -48,8 +48,9 @@ describe('va-textarea', () => {

// Render the error message text
const textareaEl = await page.find('va-textarea >>> textarea ');
expect(textareaEl.getAttribute('aria-invalid')).toEqual('true');
expect(textareaEl.getAttribute('aria-describedby')).toContain(
'error-message',
'input-error-message',
);
});

Expand Down Expand Up @@ -230,6 +231,9 @@ describe('va-textarea', () => {
const textarea = await page.find('va-textarea >>> textarea');
expect(error.innerText).toContain('This is a mistake');
expect(textarea.getAttribute('aria-invalid')).toEqual('true');
expect(textarea.getAttribute('aria-describedby')).toContain(
'input-error-message',
);
});

it('uswds v3 renders hint text', async () => {
Expand All @@ -248,7 +252,7 @@ describe('va-textarea', () => {
// Render the error message text
const textareaEl = await page.find('va-textarea >>> textarea ');
expect(textareaEl.getAttribute('aria-describedby')).toContain(
'error-message',
'input-error-message',
);
});

Expand Down
33 changes: 17 additions & 16 deletions packages/web-components/src/components/va-textarea/va-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class VaTextarea {
@Prop() uswds?: boolean = false;

/**
* Whether the component should show a character count message.
* Whether the component should show a character count message.
* Has no effect without uswds and maxlength being set.
*/
@Prop() charcount?: boolean = false;
Expand Down Expand Up @@ -154,22 +154,23 @@ export class VaTextarea {
}

render() {
const {
label,
error,
placeholder,
name,
required,
value,
hint,
uswds,
charcount,
messageAriaDescribedby
const {
label,
error,
placeholder,
name,
required,
value,
hint,
uswds,
charcount,
messageAriaDescribedby
} = this;

const maxlength = this.getMaxlength();
const ariaDescribedbyIds = `${messageAriaDescribedby ? 'input-message' : ''} ${error ? 'error-message' : ''}
${charcount && maxlength ? 'charcount-message' : ''}`.trim() || null;
const ariaDescribedbyIds = `${error ? 'input-error-message' : ''} ${
charcount && maxlength ? 'charcount-message' : ''} ${
messageAriaDescribedby ? 'input-message' : ''}`.trim() || null;

if (uswds) {
const charCountTooHigh = charcount && (value?.length > maxlength);
Expand Down Expand Up @@ -239,15 +240,15 @@ export class VaTextarea {
)}
</Host>
);
} else {
} else {
return (
<Host>
<label htmlFor="textarea">
{label}
{required && <span class="required">{i18next.t('required')}</span>}
{hint && <span class="hint-text">{hint}</span>}
</label>
<span id="error-message" role="alert">
<span id="input-error-message" role="alert">
{error && (
<Fragment>
<span class="sr-only">{i18next.t('error')}</span> {error}
Expand Down

0 comments on commit a255f32

Please sign in to comment.