Skip to content

Commit 369be9c

Browse files
authored
UI: A11y fix for disabled swagger interarctive (#31079)
* update disabled fields to be readonly * add tests for a11y fix
1 parent db78de8 commit 369be9c

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

ui/lib/open-api-explorer/addon/components/swagger-ui.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,14 @@ export default class SwaggerUiComponent extends Component {
130130
this.observer = new MutationObserver(() => {
131131
this.updateCaretTabIndex();
132132
this.updateCopyToClipboard();
133+
this.updateDisabledFields();
133134
this.updateTryItOutButtonDescription();
134135
});
135136
this.observer.observe(container, { childList: true, subtree: true });
136137
// Run once on initial load
137138
this.updateCaretTabIndex();
138139
this.updateCopyToClipboard();
140+
this.updateDisabledFields();
139141
this.updateTryItOutButtonDescription();
140142
}
141143
}
@@ -162,6 +164,13 @@ export default class SwaggerUiComponent extends Component {
162164
});
163165
}
164166

167+
updateDisabledFields() {
168+
document.querySelectorAll('.parameters :disabled').forEach((el) => {
169+
el.removeAttribute('disabled');
170+
el.setAttribute('readonly', true);
171+
});
172+
}
173+
165174
updateTryItOutButtonDescription() {
166175
document.querySelectorAll('.try-out button').forEach((el) => {
167176
const warning =

ui/mirage/factories/open-api-explorer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ export default Factory.extend({
3636
},
3737
},
3838
},
39+
'auth/token/roles/{role_name}': {
40+
description: '',
41+
get: {
42+
summary: '',
43+
tags: ['auth'],
44+
operationId: 'token-read-role',
45+
parameters: [
46+
{
47+
name: 'role_name',
48+
required: true,
49+
in: 'path',
50+
schema: {
51+
type: 'string',
52+
},
53+
description: 'Name of the role',
54+
},
55+
],
56+
responses: {
57+
200: {
58+
description: 'OK',
59+
},
60+
},
61+
},
62+
},
3963
'/secret/data/{path}': {
4064
description: 'Location of a secret.',
4165
post: {

ui/tests/integration/components/open-api-explorer/swagger-ui-test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { camelize } from '@ember/string';
1616
const SELECTORS = {
1717
container: '[data-test-swagger-ui]',
1818
searchInput: 'input.operation-filter-input',
19-
apiPathBlock: '.opblock-post',
19+
apiPathBlock: '.opblock',
2020
operationId: '.opblock-summary-operation-id',
2121
controlArrowButton: '.opblock-control-arrow',
2222
copyButton: '.copy-to-clipboard',
@@ -66,7 +66,7 @@ module('Integration | Component | open-api-explorer | swagger-ui', function (hoo
6666

6767
setNativeInputValue('token');
6868
assert.dom(SELECTORS.searchInput).hasValue('token', 'search input has value');
69-
assert.dom(SELECTORS.apiPathBlock).exists({ count: 1 }, 'renders filtered api paths');
69+
assert.dom(SELECTORS.apiPathBlock).exists({ count: 2 }, 'renders filtered api paths');
7070
});
7171

7272
test('it should render camelized operation ids', async function (assert) {
@@ -105,8 +105,13 @@ module('Integration | Component | open-api-explorer | swagger-ui', function (hoo
105105
});
106106
assert.dom(SELECTORS.copyButton).hasAttribute('tabindex', '0');
107107

108-
await click(SELECTORS.controlArrowButton);
108+
const controlArrowButton = document.querySelectorAll(SELECTORS.controlArrowButton)[1];
109+
await click(controlArrowButton);
109110
await waitFor(SELECTORS.tryItOutButton);
111+
112+
const input = document.querySelector('.parameters input:read-only');
113+
assert.dom(input).exists('parameter input is readonly');
114+
110115
assert
111116
.dom(SELECTORS.tryItOutButton)
112117
.hasAttribute(
@@ -122,7 +127,7 @@ module('Integration | Component | open-api-explorer | swagger-ui', function (hoo
122127

123128
await this.renderComponent();
124129

125-
setNativeInputValue('secret');
130+
setNativeInputValue('token');
126131

127132
await waitUntil(() => {
128133
return document.querySelector(SELECTORS.controlArrowButton).getAttribute('tabindex') === '0';
@@ -134,8 +139,12 @@ module('Integration | Component | open-api-explorer | swagger-ui', function (hoo
134139
});
135140
assert.dom(SELECTORS.copyButton).hasAttribute('tabindex', '0');
136141

137-
await click(SELECTORS.controlArrowButton);
142+
const controlArrowButton = document.querySelectorAll(SELECTORS.controlArrowButton)[1];
143+
await click(controlArrowButton);
138144
await waitFor(SELECTORS.tryItOutButton);
145+
146+
const input = document.querySelector('.parameters input:read-only');
147+
assert.dom(input).exists('parameter input is readonly');
139148
assert
140149
.dom(SELECTORS.tryItOutButton)
141150
.hasAttribute(

0 commit comments

Comments
 (0)