Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Next Release

* [#163](https://github.com/ruby-grape/grape-swagger-rails/pull/163): Copy to clipboard title - [@moskvin](https://github.com/moskvin).
* Your contribution here.

### 1.0.2 (2026/05/26)
Expand Down
41 changes: 41 additions & 0 deletions app/assets/javascripts/grape_swagger_rails/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var COPY_BUTTON_LABEL = "Copy to clipboard";
var labelCopyButtons = function (root) {
var targets = root instanceof Element && root.matches(".copy-to-clipboard")
? __spreadArray([root], Array.from(root.querySelectorAll(".copy-to-clipboard")), true) : Array.from(root.querySelectorAll(".copy-to-clipboard"));
targets.forEach(function (node) {
var el = node;
if (!el.getAttribute("title")) {
el.setAttribute("title", COPY_BUTTON_LABEL);
}
if (!el.getAttribute("aria-label")) {
el.setAttribute("aria-label", COPY_BUTTON_LABEL);
}
});
};
var safeDecodeURIComponent = function (value) {
try {
return decodeURIComponent(value);
Expand Down Expand Up @@ -232,6 +255,24 @@ var initializeSwaggerPage = function () {
bundleConfig.url = absoluteSpecUrl(options.url);
}
window.ui = SwaggerUIBundle(bundleConfig);
// Swagger UI's `.copy-to-clipboard` elements (the icon next to
// operation paths, cURL examples, OAuth redirect URLs, etc.) ship without
// a `title` or `aria-label` in some renderings, so on hover users see no
// tooltip and screen readers announce nothing. Label any unlabeled
// instances as Swagger UI renders or re-renders the tree.
labelCopyButtons(document.body);
var container = document.getElementById("swagger-ui-container");
if (container) {
new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (node.nodeType === Node.ELEMENT_NODE) {
labelCopyButtons(node);
}
});
});
}).observe(container, { childList: true, subtree: true });
}
if (selectedUrl) {
window.ui.specActions.updateUrl(selectedUrl.url);
window.ui.specActions.download(selectedUrl.url);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/grape_swagger_rails/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading