Skip to content

Commit

Permalink
Add aria label for pushbutton control
Browse files Browse the repository at this point in the history
- added aria-label for pushbutton control
- generic method to add aria label based on `aria` or `text` property

Signed-off-by: Darshan-upadhyay1110 <[email protected]>
Change-Id: I80e1aaa132ed944d24223519e640fc56d01b9dcb
  • Loading branch information
Darshan-upadhyay1110 committed Dec 25, 2024
1 parent 3d3b189 commit d03ffee
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions browser/src/control/Control.JSDialogBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ L.Control.JSDialogBuilder = L.Control.extend({
tab.id = Number.isInteger(parseInt(item.id)) ? data.id + '-' + item.id : item.id;
tab.textContent = title;
tab.setAttribute('role', 'tab');
tab.setAttribute('aria-label', title);
this._addAriaLabel(tab, item, builder);
builder._setAccessKey(tab, builder._getAccessKeyFromText(item.text));
builder._stressAccessKey(tab, tab.accessKey);

Expand Down Expand Up @@ -1597,6 +1597,8 @@ L.Control.JSDialogBuilder = L.Control.extend({
pushbutton.onclick = builder.callback.bind(builder, 'responsebutton', 'click', { id: pushbutton.id }, builder._responses[pushbutton.id], builder);
else
pushbutton.onclick = builder.callback.bind(builder, 'pushbutton', data.isToggle ? 'toggle' : 'click', pushbutton, data.command, builder);

builder._addAriaLabel(pushbutton, data, builder);

builder.map.hideRestrictedItems(data, wrapper, pushbutton);
builder.map.disableLockedItem(data, wrapper, pushbutton);
Expand Down Expand Up @@ -2224,6 +2226,13 @@ L.Control.JSDialogBuilder = L.Control.extend({
return '';
},

_addAriaLabel(element, data, builder) {
if (data.aria)
element.setAttribute('aria-label', data.aria.label);
else if(data.text)
element.setAttribute('aria-label', builder._cleanText(data.text));
},

// Create a DOM node with an identifiable parent class
_createIdentifiable : function(type, classNames, parentContainer, data) {
return L.DomUtil.create(
Expand Down Expand Up @@ -2308,10 +2317,7 @@ L.Control.JSDialogBuilder = L.Control.extend({

JSDialog.SynchronizeDisabledState(div, [button]);

if(data.text)
button.setAttribute('aria-label', data.text);
else if (data.aria)
button.setAttribute('aria-label', data.aria.label);
this._addAriaLabel(button, data, builder);

if (!data.accessKey)
builder._setAccessKey(button, builder._getAccessKeyFromText(data.text));
Expand Down

0 comments on commit d03ffee

Please sign in to comment.