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
Copy file name to clipboardExpand all lines: docs/rules/anchor-is-valid.md
+54-33
Original file line number
Diff line number
Diff line change
@@ -19,15 +19,17 @@ This is exacerbated by the expectation sighted users have of how _buttons_ and _
19
19
We are aware that sometimes _anchors_ are used instead of _buttons_ to achieve a specific visual design. When using the `<button>` element this can still be achieved with styling but, due to the meaning many people attach to the standard underlined `<a>` due its appearance, please reconsider this in the design.
All these _anchor_ implementations indicate that the element is only used to execute JavaScript code. All the above should be replaced with:
30
+
29
31
```jsx
30
-
<button onClick={foo}>Perform action</button>
32
+
<button onClick={foo}>Perform action</button>
31
33
```
32
34
33
35
### Case: I want navigable links
@@ -37,51 +39,60 @@ An `<a>` element without an `href` attribute no longer functions as a hyperlink.
37
39
To properly function as a hyperlink, the `href` attribute should be present and also contain a valid _URL_. _JavaScript_ strings, empty values or using only **#** are not considered valid `href` values.
38
40
39
41
Valid `href` attributes values are:
42
+
40
43
```jsx
41
-
<a href="/some/valid/uri">Navigate to page</a>
42
-
<a href="/some/valid/uri#top">Navigate to page and location</a>
43
-
<a href="#top">Navigate to internal page location</a>
44
+
<a href="/some/valid/uri">Navigate to page</a>
45
+
<a href="/some/valid/uri#top">Navigate to page and location</a>
46
+
<a href="#top">Navigate to internal page location</a>
44
47
```
45
48
46
-
47
49
### Case: I need the HTML to be interactive, don't I need to use an a tag for that?
48
-
An `<a>` tag is not inherently interactive. Without an href attribute, it really is no different to a `<div>`.
50
+
51
+
An `<a>` tag is not inherently interactive. Without an href attribute, it really is no different from a `<span>`.
49
52
50
53
Let's look at an example that is not accessible by all users:
If you want to navigate while providing the user with extra functionality, for example in the `onMouseEnter` event, use an anchor with an `href` attribute containing a URL or path as its value.
If you need to create an interface element that the user can mouse over or mouse out of, consider using a div element. In this case, you may need to apply a role of presentation or an interactive role. Interactive ARIA roles include `button`, `link`, `checkbox`, `menuitem`, `menuitemcheckbox`, `menuitemradio`, `option`, `radio`, `searchbox`, `switch` and `textbox`.
@@ -118,16 +129,17 @@ We recommend, without reserve, that elements resembling anchors should navigate.
118
129
119
130
However, we understand that developers are not always in total control of the visual design of web applications. In cases where it is imperative to provide an element resembling an anchor that purely acts as a click target with no navigation as result, we would like to recommend a compromise.
@@ -193,11 +208,12 @@ For the `aspects` option, these strings determine which sub-rules are run. This
193
208
194
209
The option can be used on its own or with the `components` and `specialLink` options.
195
210
196
-
If omitted, all sub-rule aspects will be run by default. This is the recommended configuration for all cases except where the rule becomes unusable due to well founded restrictions.
211
+
If omitted, all sub-rule aspects will be run by default. This is the recommended configuration for all cases except where the rule becomes unusable due to well founded restrictions.
197
212
198
213
The option must contain at least one `aspect`.
199
214
200
215
### Succeed
216
+
201
217
```jsx
202
218
<a href="https://github.com"/>
203
219
<a href="#section"/>
@@ -214,6 +230,7 @@ The option must contain at least one `aspect`.
0 commit comments