Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
/
codeql-action
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
9bfb9ba
.github
.vscode
analyze
autobuild
init
lib
node_modules
.bin
@aashutoshrathi
@actions
@ava
@azure
@babel
@chrisgavin
@eslint-community
@eslint
@github
@humanwhocodes
@nodelib
@octokit
@opentelemetry
@pkgr
@schemastore
@sinonjs
@types
@typescript-eslint
abort-controller
acorn-jsx
acorn-walk
acorn
adm-zip
aggregate-error
ajv
ansi-regex
ansi-styles
anymatch
argparse
aria-query
array-buffer-byte-length
array-find-index
array-includes
array-union
array.prototype.findlastindex
array.prototype.flat
array.prototype.flatmap
arraybuffer.prototype.slice
arrgv
ast-types-flow
asynckit
ava
available-typed-arrays
axe-core
axobject-query
balanced-match
before-after-hook
big-integer
binary-extensions
blueimp-md5
bottleneck
bplist-parser
brace-expansion
braces
browserslist
bundle-name
call-bind
callsites
caniuse-lite
cbor
chalk
check-disk-space
chokidar
chunkd
ci-info
ci-parallel-vars
clean-stack
clean-yaml-object
cli-truncate
cliui
code-excerpt
color-convert
color-name
combined-stream
common-path-prefix
concat-map
concordance
console-log-level
convert-to-spaces
cross-spawn
currently-unhandled
damerau-levenshtein
date-time
debug
deep-equal
deep-is
default-browser-id
default-browser
define-lazy-prop
define-properties
del
delayed-stream
deprecation
dequal
diff
dir-glob
doctrine
eastasianwidth
electron-to-chromium
emittery
emoji-regex
enhanced-resolve
es-abstract
es-get-iterator
es-set-tostringtag
es-shim-unscopables
es-to-primitive
escalade
escape-string-regexp
eslint-config-prettier
eslint-import-resolver-node
eslint-import-resolver-typescript
eslint-module-utils
eslint-plugin-escompat
eslint-plugin-eslint-comments
eslint-plugin-filenames
eslint-plugin-github
eslint-plugin-i18n-text
eslint-plugin-import
eslint-plugin-jsx-a11y
__mocks__
__tests__
docs/rules
accessible-emoji.md
alt-text.md
anchor-ambiguous-text.md
anchor-has-content.md
anchor-is-valid.md
aria-activedescendant-has-tabindex.md
aria-props.md
aria-proptypes.md
aria-role.md
aria-unsupported-elements.md
autocomplete-valid.md
click-events-have-key-events.md
control-has-associated-label.md
heading-has-content.md
html-has-lang.md
iframe-has-title.md
img-redundant-alt.md
interactive-supports-focus.md
label-has-associated-control.md
label-has-for.md
lang.md
media-has-caption.md
mouse-events-have-key-events.md
no-access-key.md
no-aria-hidden-on-focusable.md
no-autofocus.md
no-distracting-elements.md
no-interactive-element-to-noninteractive-role.md
no-noninteractive-element-interactions.md
no-noninteractive-element-to-interactive-role.md
no-noninteractive-tabindex.md
no-onchange.md
no-redundant-roles.md
no-static-element-interactions.md
prefer-tag-over-role.md
role-has-required-aria-props.md
role-supports-aria-props.md
scope.md
tabindex-no-positive.md
lib
node_modules
.babelrc
.eslintrc
CHANGELOG.md
LICENSE.md
README.md
package.json
eslint-plugin-no-async-foreach
eslint-plugin-no-only-tests
eslint-plugin-prettier
eslint-rule-documentation
eslint-scope
eslint-visitor-keys
eslint
espree
esprima
esquery
esrecurse
estraverse
esutils
event-target-shim
events
execa
fast-deep-equal
fast-diff
fast-glob
fast-json-stable-stringify
fast-levenshtein
fastq
figures
file-entry-cache
file-url
fill-range
find-up
flat-cache
flatted
for-each
form-data
fs.realpath
fs
fsevents
function-bind
function.prototype.name
functions-have-names
gar
get-caller-file
get-folder-size
get-intrinsic
get-stream
get-symbol-description
get-tsconfig
glob-parent
globals
globalthis
globby
gopd
graceful-fs
graphemer
has-bigints
has-property-descriptors
has-proto
has-symbols
has-tostringtag
has
human-signals
ignore-by-default
ignore
import-fresh
imurmurhash
indent-string
inflight
inherits
internal-slot
irregular-plurals
is-arguments
is-array-buffer
is-bigint
is-binary-path
is-boolean-object
is-callable
is-core-module
is-date-object
is-docker
is-error
is-extglob
is-fullwidth-code-point
is-glob
is-inside-container
is-map
is-negative-zero
is-number-object
is-number
is-path-cwd
is-path-inside
is-plain-object
is-promise
is-regex
is-set
is-shared-array-buffer
is-stream
is-string
is-symbol
is-typed-array
is-unicode-supported
is-weakmap
is-weakref
is-weakset
is-wsl
isarray
isexe
js-string-escape
js-yaml
json-schema-traverse
json-stable-stringify-without-jsonify
json-stringify-safe
json5
jsonschema
jsx-ast-utils
just-extend
language-subtag-registry
language-tags
levn
load-json-file
locate-path
lodash.camelcase
lodash.get
lodash.kebabcase
lodash.merge
lodash.snakecase
lodash.upperfirst
lodash
long
lru-cache
map-age-cleaner
matcher
md5-hex
mem
merge-stream
merge2
micromatch
mime-db
mime-types
mimic-fn
minimatch
minimist
ms
natural-compare
nise
nock
node-fetch
node-releases
nofilter
normalize-path
npm-run-path
object-inspect
object-is
object-keys
object.assign
object.entries
object.fromentries
object.groupby
object.values
once
onetime
open
optionator
p-defer
p-event
p-limit
p-locate
p-map
p-timeout
parent-module
parse-ms
path-exists
path-is-absolute
path-key
path-parse
path-to-regexp
path-type
path
picocolors
picomatch
pkg-conf
plur
prelude-ls
prettier-linter-helpers
prettier
pretty-ms
process
propagate
punycode
queue-microtask
readdirp
regenerator-runtime
regexp.prototype.flags
removeNPMAbsolutePaths
require-directory
requireindex
resolve-cwd
resolve-from
resolve-pkg-maps
resolve
reusify
rimraf
run-applescript
run-parallel
safe-array-concat
safe-regex-test
sax
semver
serialize-error
shebang-command
shebang-regex
side-channel
signal-exit
sinon
slash
slice-ansi
sprintf-js
stack-utils
stop-iteration-iterator
string-width
string.prototype.trim
string.prototype.trimend
string.prototype.trimstart
strip-ansi
strip-bom
strip-final-newline
strip-json-comments
supertap
supports-preserve-symlinks-flag
svg-element-attributes
synckit
tapable
temp-dir
text-table
time-zone
tiny-each-async
titleize
tmp-promise
tmp
to-regex-range
tr46
ts-api-utils
tsconfig-paths
tslib
tunnel
type-check
type-detect
type-fest
typed-array-buffer
typed-array-byte-length
typed-array-byte-offset
typed-array-length
typescript
unbox-primitive
universal-user-agent
untildify
update-browserslist-db
uri-js
util
uuid
webidl-conversions
well-known-symbols
whatwg-url
which-boxed-primitive
which-collection
which-typed-array
which
wrap-ansi
wrappy
write-file-atomic
xml2js
xmlbuilder
y18n
yallist
yargs-parser
yargs
yocto-queue
zlib
.package-lock.json
pr-checks
python-setup
queries
resolve-environment
src
tests
upload-sarif
.editorconfig
.eslintignore
.eslintrc.json
.git-blame-ignore-revs
.gitattributes
.gitignore
.npmrc
CHANGELOG.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
package-lock.json
package.json
tsconfig.json
Breadcrumbs
codeql-action
/
node_modules
/
eslint-plugin-jsx-a11y
/
docs
/
rules
/
control-has-associated-label.md
Blame
Blame
Latest commit
Henry Mercer
Bump packages to fix linter
Jan 18, 2023
0a11e3f
·
Jan 18, 2023
History
History
113 lines (86 loc) · 3.72 KB
Breadcrumbs
codeql-action
/
node_modules
/
eslint-plugin-jsx-a11y
/
docs
/
rules
/
control-has-associated-label.md
Top
File metadata and controls
Preview
Code
Blame
113 lines (86 loc) · 3.72 KB
Raw
# jsx-a11y/control-has-associated-label 🚫 This rule is _disabled_ in the following configs: ☑️ `recommended`, 🔒 `strict`. <!-- end auto-generated rule header --> Enforce that a control (an interactive element) has a text label. There are two supported ways to supply a control with a text label: - Provide text content inside the element. - Use the `aria-label` attribute on the element, with a text value. - Use the `aria-labelledby` attribute on the element, and point the IDREF value to an element with an accessible label. - Alternatively, with an `img` tag, you may use the `alt` attribute to supply a text description of the image. The rule is permissive in the sense that it will assume that expressions will eventually provide a label. So an element like this will pass. ```jsx <button type="button">{maybeSomethingThatContainsALabel}</button> ``` ## How do I resolve this error? ### Case: I have a simple button that requires a label. Provide text content in the `button` element. ```jsx <button type="button">Save</button> ``` ### Case: I have an icon button and I don't want visible text. Use the `aria-label` attribute and provide the text label as the value. ```jsx <button type="button" aria-label="Save" class="icon-save" /> ``` ### Case: The label for my element is already located on the page and I don't want to repeat the text in my source code. Use the `aria-labelledby` attribute and point the IDREF value to an element with an accessible label. ```jsx <div id="js_1">Comment</div> <textarea aria-labelledby="js_1"></textarea> ``` ### Case: My label and input components are custom components, but I still want to require that they have an accessible text label. You can configure the rule to be aware of your custom components. Refer to the Rule Details below. ```jsx <CustomInput label="Surname" type="text" value={value} /> ``` ## Rule options This rule takes one optional object argument of type object: ```json { "rules": { "jsx-a11y/control-has-associated-label": [ 2, { "labelAttributes": ["label"], "controlComponents": ["CustomComponent"], "ignoreElements": [ "audio", "canvas", "embed", "input", "textarea", "tr", "video", ], "ignoreRoles": [ "grid", "listbox", "menu", "menubar", "radiogroup", "row", "tablist", "toolbar", "tree", "treegrid", ], "depth": 3, }], } } ``` - `labelAttributes` is a list of attributes to check on the control component and its children for a label. Use this if you have a custom component that uses a string passed on a prop to render an HTML `label`, for example. - `controlComponents` is a list of custom React Components names that will render down to an interactive element. - `ignoreElements` is an array of elements that should not be considered control (interactive) elements and therefore they do not require a text label. - `ignoreRoles` is an array of ARIA roles that should not be considered control (interactive) roles and therefore they do not require a text label. - `depth` (default 2, max 25) is an integer that determines how deep within a `JSXElement` the rule should look for text content or an element with a label to determine if the interactive element will have an accessible label. ### Succeed ```jsx <button type="button" aria-label="Save" class="icon-save" /> ``` ### Fail ```jsx <button type="button" class="icon-save" /> ``` ## Accessibility guidelines - [WCAG 1.3.1](https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships) - [WCAG 3.3.2](https://www.w3.org/WAI/WCAG21/Understanding/labels-or-instructions) - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
You can’t perform that action at this time.