-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(a11y): indicate required form controls using an asterisk (#1723)
Co-authored-by: Dan Cormier <dcormier@stackoverflow.com>
- Loading branch information
1 parent
00d8538
commit 457404b
Showing
186 changed files
with
514 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,6 @@ | ||
import { html } from "@open-wc/testing"; | ||
import { runA11yTests } from "../../test/a11y-test-utils"; | ||
import "../../index"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const labelTemplate = ({ component, testid }: any) => { | ||
return html` | ||
<fieldset data-testid="${testid}" class="p8 ws3">${component}</fieldset> | ||
`; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const getChildren = (status?: any) => { | ||
const typeClass = | ||
status && status !== "base" ? `s-label--status__${status}` : ""; | ||
return ` | ||
Example label | ||
${ | ||
status | ||
? ` | ||
<span class="s-label--status ${typeClass}">${ | ||
status ?? "no type" | ||
}</span> | ||
` | ||
: "" | ||
} | ||
`; | ||
}; | ||
import getTestArgs from "./label.test.setup"; | ||
|
||
describe("label", () => { | ||
runA11yTests({ | ||
baseClass: `s-label`, | ||
modifiers: { | ||
primary: ["sm", "md", "lg", "xl"], | ||
}, | ||
children: { | ||
"default": getChildren(), | ||
"status": getChildren("base"), | ||
"status-beta": getChildren("beta"), | ||
"status-new": getChildren("new"), | ||
"status-required": getChildren("required"), | ||
}, | ||
tag: "label", | ||
template: ({ component, testid }) => | ||
labelTemplate({ component, testid }), | ||
}); | ||
runA11yTests(getTestArgs()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { html } from "@open-wc/testing"; | ||
import type { TestVariationArgs } from "../../test/test-utils"; | ||
import "../../index"; | ||
|
||
type StatusType = "base" | "beta" | "new" | "required"; | ||
|
||
const labelTemplate = ({ | ||
component, | ||
testid, | ||
disabled, | ||
}: { | ||
component: unknown; | ||
testid: string; | ||
disabled: boolean; | ||
}) => { | ||
return html` | ||
<fieldset | ||
data-testid="${testid}" | ||
class="p8 ws3" | ||
?disabled="${disabled}" | ||
> | ||
${component} | ||
</fieldset> | ||
`; | ||
}; | ||
|
||
const getStatus = (status: StatusType | undefined) => { | ||
if (!status) return ""; | ||
const statusTypeClass = | ||
status !== "base" ? `s-label--status__${status}` : ""; | ||
return `<span class="s-label--status ${statusTypeClass}">${status}</span>`; | ||
}; | ||
|
||
const getRequiredSymbol = (required: boolean | undefined) => { | ||
return required | ||
? `<abbr class="s-required-symbol" title="required">*</abbr>` | ||
: ""; | ||
}; | ||
|
||
const getChildren = (text: string, status?: StatusType, required?: boolean) => { | ||
return `${text}${getRequiredSymbol(required)} ${getStatus(status)}`; | ||
}; | ||
|
||
const getTestArgs = (disabled = false): TestVariationArgs => { | ||
const text = disabled ? "Disabled label" : "Example label"; | ||
const prefix = disabled ? "disabled-" : ""; | ||
|
||
return { | ||
baseClass: `s-label`, | ||
modifiers: { | ||
primary: ["sm", "md", "lg", "xl"], | ||
}, | ||
children: { | ||
[`${prefix}default`]: getChildren(text), | ||
[`${prefix}required`]: getChildren(text, undefined, true), | ||
[`${prefix}status`]: getChildren(text, "base"), | ||
[`${prefix}status-beta`]: getChildren(text, "beta"), | ||
[`${prefix}status-new`]: getChildren(text, "new"), | ||
[`${prefix}status-required`]: getChildren(text, "required"), | ||
}, | ||
tag: "label", | ||
template: ({ component, testid }) => | ||
labelTemplate({ component, testid, disabled }), | ||
}; | ||
}; | ||
|
||
export default getTestArgs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,8 @@ | ||
import { html } from "@open-wc/testing"; | ||
import { runVisualTests } from "../../test/visual-test-utils"; | ||
import "../../index"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const labelTemplate = ({ component, testid, isDisabled }: any) => { | ||
return html` | ||
<fieldset | ||
data-testid="${testid}" | ||
class="p8 ws3" | ||
?disabled="${isDisabled}" | ||
> | ||
${component} | ||
</fieldset> | ||
`; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const getChildren = (text: string, status?: any) => { | ||
const typeClass = | ||
status && status !== "base" ? `s-label--status__${status}` : ""; | ||
return ` | ||
${text} | ||
${ | ||
status | ||
? ` | ||
<span class="s-label--status ${typeClass}">${ | ||
status ?? "no type" | ||
}</span> | ||
` | ||
: "" | ||
} | ||
`; | ||
}; | ||
import getTestArgs from "./label.test.setup"; | ||
|
||
describe("label", () => { | ||
[true, false].forEach((isDisabled) => { | ||
const text = isDisabled ? "Disabled label" : "Example label"; | ||
|
||
runVisualTests({ | ||
baseClass: `s-label`, | ||
modifiers: { | ||
primary: ["sm", "md", "lg", "xl"], | ||
}, | ||
children: isDisabled | ||
? { | ||
"disabled": getChildren(text), | ||
"disabled-status": getChildren(text, "base"), | ||
"disabled-status-beta": getChildren(text, "beta"), | ||
"disabled-status-new": getChildren(text, "new"), | ||
"disabled-status-required": getChildren(text, "required"), | ||
} | ||
: { | ||
"default": getChildren(text), | ||
"status": getChildren(text, "base"), | ||
"status-beta": getChildren(text, "beta"), | ||
"status-new": getChildren(text, "new"), | ||
"status-required": getChildren(text, "required"), | ||
}, | ||
tag: "label", | ||
template: ({ component, testid }) => | ||
labelTemplate({ component, testid, isDisabled }), | ||
}); | ||
[true, false].forEach((disabled) => { | ||
runVisualTests(getTestArgs(disabled)); | ||
}); | ||
}); |
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-dark-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-dark-lg-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-dark-md-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-dark-sm-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-dark-xl-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-lg-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-lg-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-md-disabled-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-md-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-sm-disabled-required.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-sm-required.png
Oops, something went wrong.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-xl-disabled-required.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-dark-xl-required.png
Oops, something went wrong.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-disabled-required.png
Oops, something went wrong.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-lg-disabled-required.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-lg-required.png
Oops, something went wrong.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-md-disabled-required.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-md-required.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-required.png
Oops, something went wrong.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
screenshots/Chromium/baseline/s-label-highcontrast-light-sm-disabled-required.png
Oops, something went wrong.
Oops, something went wrong.