From 94673a10287e96c0df89bbb48702eeeb101dba68 Mon Sep 17 00:00:00 2001 From: Leilei332 Date: Tue, 7 Oct 2025 20:05:09 +0800 Subject: [PATCH] Allow button widget to use all ARIA attibutes (#9154) * Allow button widget to use all ARIA attibutes * Add link in docs * Update docs --- core/modules/widgets/button.js | 12 ++++++++---- editions/tw5.com/tiddlers/widgets/ButtonWidget.tid | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/modules/widgets/button.js b/core/modules/widgets/button.js index 68f2fcd11..8f6f14376 100644 --- a/core/modules/widgets/button.js +++ b/core/modules/widgets/button.js @@ -61,6 +61,10 @@ ButtonWidget.prototype.render = function(parent,nextSibling) { sourcePrefix: "data-", destPrefix: "data-" }); + this.assignAttributes(domNode,{ + sourcePrefix: "aria-", + destPrefix: "aria-" + }); // Assign other attributes if(this.style) { domNode.setAttribute("style",this.style); @@ -68,9 +72,6 @@ ButtonWidget.prototype.render = function(parent,nextSibling) { if(this.tooltip) { domNode.setAttribute("title",this.tooltip); } - if(this["aria-label"]) { - domNode.setAttribute("aria-label",this["aria-label"]); - } if (this.role) { domNode.setAttribute("role", this.role); } @@ -215,7 +216,6 @@ ButtonWidget.prototype.execute = function() { this.setTo = this.getAttribute("setTo"); this.popup = this.getAttribute("popup"); this.hover = this.getAttribute("hover"); - this["aria-label"] = this.getAttribute("aria-label"); this.role = this.getAttribute("role"); this.tooltip = this.getAttribute("tooltip"); this.style = this.getAttribute("style"); @@ -271,6 +271,10 @@ ButtonWidget.prototype.refresh = function(changedTiddlers) { sourcePrefix: "data-", destPrefix: "data-" }); + this.assignAttributes(this.domNodes[0],{ + sourcePrefix: "aria-", + destPrefix: "aria-" + }); } return this.refreshChildren(changedTiddlers); }; diff --git a/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid b/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid index c726360bd..d1e94283c 100644 --- a/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid @@ -1,6 +1,6 @@ caption: button created: 20131024141900000 -modified: 20250720031248375 +modified: 20250720025737830 tags: Widgets TriggeringWidgets title: ButtonWidget type: text/vnd.tiddlywiki @@ -44,6 +44,7 @@ The content of the `<$button>` widget is displayed within the button. |class |An optional CSS class name to be assigned to the HTML element| |data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element | |style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element | +|aria-* |<<.from-version "5.4.0">> Optional [[ARIA attributes|https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes]]. | |style |An optional CSS style attribute to be assigned to the HTML element | |tag |An optional html tag to use instead of the default "button" | |dragTiddler |An optional tiddler title making the button draggable and identifying the payload tiddler. See DraggableWidget for details |