ontotext-yasgui-web-component 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,7 +29,6 @@ export class TooltipService {
29
29
  static updateTooltipData(element, tooltip) {
30
30
  if (tooltip) {
31
31
  element.setAttribute('yasgui-data-tooltip', tooltip);
32
- element.setAttribute("aria-label", tooltip);
33
32
  }
34
33
  }
35
34
  static updatePlacement(element, placement) {
@@ -24,14 +24,11 @@ export class YasqeService {
24
24
  }
25
25
  onLanguageChange(_currentLang) {
26
26
  let button = document.querySelector(`.${YasqeService.getActionButtonClassName(YasqeButtonName.CREATE_SAVED_QUERY)}`);
27
- let tooltip = this.translationService.translate('yasqe.actions.save_query.button.tooltip');
28
- TooltipService.updateTooltip(button, tooltip);
27
+ this.updateLabel(button, 'yasqe.actions.save_query.button.tooltip');
29
28
  button = document.querySelector(`.${YasqeService.getActionButtonClassName(YasqeButtonName.SHOW_SAVED_QUERIES)}`);
30
- tooltip = this.translationService.translate('yasqe.actions.show_saved_queries.button.tooltip');
31
- TooltipService.updateTooltip(button, tooltip);
29
+ this.updateLabel(button, 'yasqe.actions.show_saved_queries.button.tooltip');
32
30
  button = document.querySelector(`.${YasqeService.getActionButtonClassName(YasqeButtonName.SHARE_QUERY)}`);
33
- tooltip = this.translationService.translate('yasqe.actions.share_query.button.tooltip');
34
- TooltipService.updateTooltip(button, tooltip);
31
+ this.updateLabel(button, 'yasqe.actions.share_query.button.tooltip');
35
32
  const ontotextYasgui = this.yasguiBuilder.getInstance();
36
33
  const yasqe = ontotextYasgui === null || ontotextYasgui === void 0 ? void 0 : ontotextYasgui.getYasqe();
37
34
  if (ontotextYasgui && yasqe) {
@@ -47,6 +44,22 @@ export class YasqeService {
47
44
  }
48
45
  }
49
46
  }
47
+ /**
48
+ * Sets the translated label as both tooltip and accessible name of an icon-only button.
49
+ */
50
+ updateLabel(button, labelKey) {
51
+ if (!button) {
52
+ return;
53
+ }
54
+ const label = this.translationService.translate(labelKey);
55
+ button.setAttribute('aria-label', label);
56
+ TooltipService.updateTooltip(button, label);
57
+ }
58
+ addLabelledTooltip(button, labelKey) {
59
+ const tooltipElement = TooltipService.addTooltip(button);
60
+ this.updateLabel(button, labelKey);
61
+ return tooltipElement;
62
+ }
50
63
  static initPluginButtonNameToClassNameMapping() {
51
64
  YasqeService.pluginButtonNameToClassNameMapping = new Map();
52
65
  YasqeService.pluginButtonNameToClassNameMapping.set(YasqeButtonName.FULLSCREEN, `yasqe_${YasqeButtonName.FULLSCREEN}Button`);
@@ -121,8 +134,7 @@ export class YasqeService {
121
134
  const handleShowSavedQuery = () => this.eventService.emit(new InternalShowSavedQueriesEvent(buttonElement));
122
135
  buttonElement.addEventListener('click', handleShowSavedQuery);
123
136
  yasqe.addDestroyCallback(() => buttonElement.removeEventListener('click', handleShowSavedQuery));
124
- const tooltip = this.translationService.translate('yasqe.actions.show_saved_queries.button.tooltip');
125
- return TooltipService.addTooltip(buttonElement, tooltip);
137
+ return this.addLabelledTooltip(buttonElement, 'yasqe.actions.show_saved_queries.button.tooltip');
126
138
  }
127
139
  buildCreateSaveQueryButton(yasqe) {
128
140
  const buttonElement = document.createElement('button');
@@ -130,8 +142,7 @@ export class YasqeService {
130
142
  const handleCreateSaveQuery = () => this.eventService.emit(new InternalCreateSavedQueryEvent());
131
143
  buttonElement.addEventListener('click', handleCreateSaveQuery);
132
144
  yasqe.addDestroyCallback(() => buttonElement.removeEventListener('click', handleCreateSaveQuery));
133
- const tooltip = this.translationService.translate('yasqe.actions.save_query.button.tooltip');
134
- return TooltipService.addTooltip(buttonElement, tooltip);
145
+ return this.addLabelledTooltip(buttonElement, 'yasqe.actions.save_query.button.tooltip');
135
146
  }
136
147
  buildShareQueryButton(yasqe) {
137
148
  const buttonElement = document.createElement('button');
@@ -139,8 +150,7 @@ export class YasqeService {
139
150
  const handleShareQuery = () => this.eventService.emit(new InternalShareQueryEvent());
140
151
  buttonElement.addEventListener('click', handleShareQuery);
141
152
  yasqe.addDestroyCallback(() => buttonElement.removeEventListener('click', handleShareQuery));
142
- const tooltip = this.translationService.translate('yasqe.actions.share_query.button.tooltip');
143
- return TooltipService.addTooltip(buttonElement, tooltip);
153
+ return this.addLabelledTooltip(buttonElement, 'yasqe.actions.share_query.button.tooltip');
144
154
  }
145
155
  buildInferAndSameAsButtons(yasguiConfiguration, yasqe) {
146
156
  // When a new tab is open and infer action is configured to be visible infer and sameAs are undefined, so we have to initialized them.
@@ -203,6 +213,9 @@ export class YasqeService {
203
213
  const sameAsButtonElement = sameAsTooltipElement.querySelector('button');
204
214
  const sameAsTitleLabelKey = inferred ? `yasqe.actions.expand_results_same_as.${sameAs}.button.tooltip` : 'yasqe.actions.expand_results_same_as.disable.button.tooltip';
205
215
  TooltipService.updateTooltip(sameAsButtonElement, this.translationService.translate(sameAsTitleLabelKey));
216
+ sameAsButtonElement.setAttribute('aria-label', this.translationService.translate('yasqe.actions.expand_results_same_as.button.label'));
217
+ sameAsButtonElement.setAttribute('aria-pressed', `${sameAs}`);
218
+ sameAsButtonElement.removeAttribute('aria-disabled');
206
219
  sameAsButtonElement.classList.remove('icon-same-as-on', 'icon-same-as-off', 'disabled');
207
220
  if (sameAs) {
208
221
  sameAsButtonElement.classList.add('icon-same-as-on');
@@ -213,12 +226,15 @@ export class YasqeService {
213
226
  if (!inferred) {
214
227
  // Disables the same as button. The Disabled attribute is not used because it stops firing events and breaks the button tooltip.
215
228
  sameAsButtonElement.classList.add('disabled');
229
+ sameAsButtonElement.setAttribute('aria-disabled', 'true');
216
230
  }
217
231
  }
218
232
  updateInferredElement(inferredElement, sameAsElement, inferred, sameAs) {
219
233
  const inferredButtonElement = inferredElement.querySelector('button');
220
234
  const inferredButtonTitle = this.translationService.translate(`yasqe.actions.include_inferred.${inferred}.button.tooltip`);
221
235
  TooltipService.updateTooltip(inferredButtonElement, inferredButtonTitle);
236
+ inferredButtonElement.setAttribute('aria-label', this.translationService.translate('yasqe.actions.include_inferred.button.label'));
237
+ inferredButtonElement.setAttribute('aria-pressed', `${inferred}`);
222
238
  inferredButtonElement.classList.remove('icon-inferred-on', 'icon-inferred-off');
223
239
  if (inferred) {
224
240
  inferredButtonElement.classList.add('icon-inferred-on');