Skip to content

Commit

Permalink
Merge pull request #641 from City-of-Helsinki/UHF-7853-notification-c…
Browse files Browse the repository at this point in the history
…omponents-accessibility

UHF-7853: Notification components accessibility
  • Loading branch information
jeremysteerio authored May 2, 2023
2 parents 92fbe47 + 9119f91 commit 13d3370
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
18 changes: 18 additions & 0 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1547,3 +1547,21 @@ function hdbt_preprocess_paragraph__school_search(array &$variables): void {
$variables['#attached']['drupalSettings']['helfi_school_search']['cookie_privacy_url'] = $privacyUrl->toString();
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_node__announcement(array &$variables) {
$type = $variables['node']->get('field_announcement_type')->value;

$type_label = match($type) {
'alert' => t('Alert'),
'attention' => t('Attention'),
default => t('Notification')
};

$close_label = t('Close');

$variables['type_label'] = $type_label;
$variables['close_label'] = $close_label;
}
6 changes: 3 additions & 3 deletions templates/content/node--announcement--default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% set link = content.field_announcement_link[0] %}

<div class="announcement js-announcement {{ block_modifier }} container" data-uuid="{{ node.uuid.value }}">
<section aria-label={{ type_label }} class="announcement js-announcement {{ block_modifier }} container" data-uuid="{{ node.uuid.value }}">
<div class="announcement__container">
<div class="announcement__content">
{% if content.body|render != null %}
Expand All @@ -23,7 +23,7 @@
{% endif %}
</div>
<button type="button" class="announcement__close js-announcement__close--disabled" aria-labelledby="announcement__close__aria-label">
<span id="announcement__close__aria-label" class="is-hidden">{{ "Close announcement"|t }}</span>
<span id="announcement__close__aria-label" class="is-hidden">{{ [close_label, type_label|lower]|join(" ") }}</span>
</button>
</div>
</div>
</section>
2 changes: 1 addition & 1 deletion templates/misc/status-messages.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<section data-drupal-messages aria-label="{{ 'Notification'|t }}" class="{{ section_classes|without('messages-list')|join(' ') }}" {{ alternative_language ? create_attribute(({ 'lang': lang_attributes.fallback_lang, 'dir': lang_attributes.fallback_dir })) }}>
{% set is_message_with_title = status_headings[type] %}
{% set is_message_with_icon = type in ['error', 'default', 'warning', 'success'] %}
<div role="contentinfo" aria-labelledby="{{ title_ids[type] }}" class="{{ classes|without('messages-list__item')|join(' ') }}">
<div class="{{ classes|without('messages-list__item')|join(' ') }}">
{% if is_message_with_title or is_message_with_icon %}
{% if is_message_with_title %}
<div class="hds-notification__label" role="heading" aria-level="2">
Expand Down

0 comments on commit 13d3370

Please sign in to comment.