Skip to content

Commit 4e43130

Browse files
authored
feat(a11y): support alt tags for images
This PR adds a bit of more a11y support to toast, dropdown and search when it comes to generate images and adding an optional alt-attribute new option alt for toast (will be used when showImage is used as well) support for alt key in search response object (will be used if an image key is given as well) support for alt as dropdown-item key (will be used if an image key is given as well)
1 parent 8b6456b commit 4e43130

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/definitions/modules/dropdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4180,6 +4180,7 @@
41804180
type: 'type', // type of dropdown element
41814181
image: 'image', // optional image path
41824182
imageClass: 'imageClass', // optional individual class for image
4183+
alt: 'alt', // optional alt text for image
41834184
icon: 'icon', // optional icon name
41844185
iconClass: 'iconClass', // optional individual class for icon (for example to use flag instead)
41854186
class: 'class', // optional individual class for item/header
@@ -4357,7 +4358,7 @@
43574358
html += '<i class="' + (itemType.indexOf('left') !== -1 ? 'left' : '') + ' dropdown icon"></i>';
43584359
}
43594360
if (option[fields.image]) {
4360-
html += '<img class="' + deQuote(option[fields.imageClass] || className.image) + '" src="' + deQuote(option[fields.image]) + '">';
4361+
html += '<img class="' + deQuote(option[fields.imageClass] || className.image) + '" src="' + deQuote(option[fields.image]) + (option[fields.alt] ? '" alt="' + deQuote(option[fields.alt]) : '') + '">';
43614362
}
43624363
if (option[fields.icon]) {
43634364
html += '<i class="' + deQuote(option[fields.icon] + ' ' + (option[fields.iconClass] || className.icon)) + '"></i>';

src/definitions/modules/search.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@
14441444
categoryResults: 'results', // array of results (category view)
14451445
description: 'description', // result description
14461446
image: 'image', // result image
1447+
alt: 'alt', // result alt text for image
14471448
price: 'price', // result price
14481449
results: 'results', // array of results (standard)
14491450
title: 'title', // result title
@@ -1531,7 +1532,7 @@
15311532
if (result[fields.image] !== undefined) {
15321533
html += ''
15331534
+ '<div class="image">'
1534-
+ ' <img src="' + result[fields.image].replace(/"/g, '') + '">'
1535+
+ ' <img src="' + result[fields.image].replace(/"/g, '') + (result[fields.alt] ? '" alt="' + result[fields.alt].replace(/"/g, '') : '') + '">'
15351536
+ '</div>';
15361537
}
15371538
html += '<div class="content">';
@@ -1584,7 +1585,7 @@
15841585
if (result[fields.image] !== undefined) {
15851586
html += ''
15861587
+ '<div class="image">'
1587-
+ ' <img src="' + result[fields.image].replace(/"/g, '') + '">'
1588+
+ ' <img src="' + result[fields.image].replace(/"/g, '') + (result[fields.alt] ? '" alt="' + result[fields.alt].replace(/"/g, '') : '') + '">'
15881589
+ '</div>';
15891590
}
15901591
html += '<div class="content">';

src/definitions/modules/toast.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
$toast.append($('<img>', {
184184
class: className.image + ' ' + settings.classImage,
185185
src: settings.showImage,
186+
alt: settings.alt || '',
186187
}));
187188
}
188189
if (settings.title !== '') {
@@ -228,7 +229,7 @@
228229
$toast.find(selector.icon).attr('class', iconClass + ' ' + className.icon);
229230
}
230231
if (settings.showImage) {
231-
$toast.find(selector.image).attr('src', settings.showImage);
232+
$toast.find(selector.image).attr('src', settings.showImage).attr('alt', settings.alt || '');
232233
}
233234
if (settings.title !== '') {
234235
$toast.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML));
@@ -841,6 +842,7 @@
841842
actions: false,
842843
preserveHTML: true,
843844
showImage: false,
845+
alt: false,
844846

845847
// transition settings
846848
transition: {

0 commit comments

Comments
 (0)