Skip to content

Commit 2380d4e

Browse files
author
Jens Vannerum
committed
fix bug in lint rule, add docs for rule and update name so it's clear this is only for buttons currently
1 parent 7ade453 commit 2380d4e

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
"rules": {
295295
// Custom DSpace Angular rules
296296
"dspace-angular-html/themed-component-usages": "error",
297-
"dspace-angular-html/no-disabled-attr": "error"
297+
"dspace-angular-html/no-disabled-attribute-on-button": "error"
298298
}
299299
},
300300
{

docs/lint/html/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
_______
33

44
- [`dspace-angular-html/themed-component-usages`](./rules/themed-component-usages.md): Themeable components should be used via the selector of their `ThemedComponent` wrapper class
5+
- [`dspace-angular-html/no-disabled-attribute-on-button`](./rules/no-disabled-attribute-on-button.md): Buttons should use the `dsBtnDisabled` directive instead of the HTML `disabled` attribute.

lint/src/rules/html/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
bundle,
1111
RuleExports,
1212
} from '../../util/structure';
13-
import * as noDisabledAttr from './no-disabled-attr';
13+
import * as noDisabledAttributeOnButton from './no-disabled-attribute-on-button';
1414
import * as themedComponentUsages from './themed-component-usages';
1515

1616
const index = [
1717
themedComponentUsages,
18-
noDisabledAttr,
18+
noDisabledAttributeOnButton,
1919

2020
] as unknown as RuleExports[];
2121

lint/src/rules/html/no-disabled-attr.ts renamed to lint/src/rules/html/no-disabled-attribute-on-button.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
TmplAstBoundAttribute,
3-
TmplAstTextAttribute
3+
TmplAstTextAttribute,
44
} from '@angular-eslint/bundled-angular-compiler';
55
import { TemplateParserServices } from '@angular-eslint/utils';
66
import {
77
ESLintUtils,
88
TSESLint,
99
} from '@typescript-eslint/utils';
10+
1011
import {
1112
DSpaceESLintRuleInfo,
1213
NamedTests,
@@ -18,10 +19,12 @@ export enum Message {
1819
}
1920

2021
export const info = {
21-
name: 'no-disabled-attr',
22+
name: 'no-disabled-attribute-on-button',
2223
meta: {
2324
docs: {
24-
description: `Buttons should use the \`dsBtnDisabled\` directive instead of the HTML \`disabled\` attribute for accessibility reasons.`,
25+
description: `Buttons should use the \`dsBtnDisabled\` directive instead of the HTML \`disabled\` attribute.
26+
This should be done to ensure that users with a screen reader are able to understand that the a button button is present, and that it is disabled.
27+
The native html disabled attribute does not allow users to navigate to the button by keyboard, and thus they have no way of knowing that the button is present.`,
2528
},
2629
type: 'problem',
2730
fixable: 'code',
@@ -52,7 +55,7 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
5255
*/
5356
function replaceDisabledText(text: string ): string {
5457
const hasBrackets = text.includes('[') && text.includes(']');
55-
const newDisabledText = hasBrackets ? 'dsBtnDisabled' : '[dsBtnDisabled]';
58+
const newDisabledText = hasBrackets ? 'dsBtnDisabled' : '[dsBtnDisabled]="true"';
5659
return text.replace('disabled', newDisabledText);
5760
}
5861

@@ -101,7 +104,7 @@ export const tests = {
101104
{
102105
name: 'disabled attribute is still valid on non-button elements',
103106
code: `
104-
<input disabled="true">
107+
<input disabled>
105108
`,
106109
},
107110
{
@@ -121,7 +124,7 @@ export const tests = {
121124
{
122125
name: 'should not use disabled attribute in HTML templates',
123126
code: `
124-
<button disabled="true">Submit</button>
127+
<button disabled>Submit</button>
125128
`,
126129
errors: [{ messageId: Message.USE_DSBTN_DISABLED }],
127130
output: `

0 commit comments

Comments
 (0)