mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #2770 from alphagov/announce-selection-count-to-assistive-tech
Announce selection count to assistive tech
This commit is contained in:
@@ -10,10 +10,10 @@
|
|||||||
// which field is visible.
|
// which field is visible.
|
||||||
this.$form.find('button[value=unknown]').remove();
|
this.$form.find('button[value=unknown]').remove();
|
||||||
|
|
||||||
this.$stickyBottom = this.$form.find('#sticky_template_forms');
|
this.$liveRegionCounter = this.$form.find('.selection-counter');
|
||||||
|
|
||||||
this.$stickyBottom.append(this.nothingSelectedButtons);
|
this.$liveRegionCounter.before(this.nothingSelectedButtons);
|
||||||
this.$stickyBottom.append(this.itemsSelectedButtons);
|
this.$liveRegionCounter.before(this.itemsSelectedButtons);
|
||||||
|
|
||||||
// all the diff states that we want to show or hide
|
// all the diff states that we want to show or hide
|
||||||
this.states = [
|
this.states = [
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
// first off show the new template / new folder buttons
|
// first off show the new template / new folder buttons
|
||||||
this.currentState = this.$form.data('prev-state') || 'unknown';
|
this.currentState = this.$form.data('prev-state') || 'unknown';
|
||||||
if (this.currentState === 'unknown') {
|
if (this.currentState === 'unknown') {
|
||||||
this.selectActionButtons(false);
|
this.selectActionButtons();
|
||||||
} else {
|
} else {
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
@@ -76,44 +76,61 @@
|
|||||||
|
|
||||||
this.addCancelButton = function(state) {
|
this.addCancelButton = function(state) {
|
||||||
let selector = `[value=${state.key}]`;
|
let selector = `[value=${state.key}]`;
|
||||||
let $cancel = this.makeButton('Cancel', () => {
|
let $cancel = this.makeButton('Cancel', {
|
||||||
|
'onclick': () => {
|
||||||
|
|
||||||
// clear existing data
|
// clear existing data
|
||||||
state.$el.find('input:radio').prop('checked', false);
|
state.$el.find('input:radio').prop('checked', false);
|
||||||
state.$el.find('input:text').val('');
|
state.$el.find('input:text').val('');
|
||||||
|
|
||||||
// go back to action buttons
|
// go back to action buttons
|
||||||
this.selectActionButtons(selector);
|
this.selectActionButtons(selector);
|
||||||
}, selector);
|
},
|
||||||
|
'cancelSelector': selector,
|
||||||
|
'nonvisualText': "this step"
|
||||||
|
});
|
||||||
|
|
||||||
state.$el.find('[type=submit]').after($cancel);
|
state.$el.find('[type=submit]').after($cancel);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addClearButton = function(state) {
|
this.addClearButton = function(state) {
|
||||||
|
let selector = 'button[value=add-new-template]';
|
||||||
|
let $clear = this.makeButton('Clear', {
|
||||||
|
'onclick': () => {
|
||||||
|
|
||||||
let $clear = this.makeButton('Clear', () => {
|
// uncheck all templates and folders
|
||||||
// uncheck all templates and folders
|
this.$form.find('input:checkbox').prop('checked', false);
|
||||||
this.$form.find('input:checkbox').prop('checked', false);
|
|
||||||
|
|
||||||
// go back to action buttons
|
// go back to action buttons
|
||||||
this.selectActionButtons();
|
this.selectActionButtons(selector);
|
||||||
|
},
|
||||||
|
'nonvisualText': "selection"
|
||||||
});
|
});
|
||||||
|
|
||||||
state.$el.find('.template-list-selected-counter').append($clear);
|
state.$el.find('.template-list-selected-counter').append($clear);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.makeButton = (text, fn, cancelSelector) => $('<a></a>')
|
this.makeButton = (text, opts) => {
|
||||||
.html(text)
|
let $btn = $('<a href=""></a>')
|
||||||
.addClass('js-cancel')
|
.html(text)
|
||||||
.data('target', cancelSelector) // isn't set if cancelSelector is undefined
|
.addClass('js-cancel')
|
||||||
.attr('tabindex', '0')
|
// isn't set if cancelSelector is undefined
|
||||||
.on('click keydown', event => {
|
.data('target', opts.cancelSelector || undefined)
|
||||||
// space, enter or no keyCode (must be mouse input)
|
.attr('tabindex', '0')
|
||||||
if ([13, 32, undefined].indexOf(event.keyCode) > -1) {
|
.on('click keydown', event => {
|
||||||
event.preventDefault();
|
// space, enter or no keyCode (must be mouse input)
|
||||||
fn();
|
if ([13, 32, undefined].indexOf(event.keyCode) > -1) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (opts.hasOwnProperty('onclick')) { opts.onclick(); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (opts.hasOwnProperty('nonvisualText')) {
|
||||||
|
$btn.append(`<span class="visuallyhidden"> ${opts.nonvisualText}</span>`);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return $btn;
|
||||||
|
};
|
||||||
|
|
||||||
this.selectActionButtons = function (targetSelector) {
|
this.selectActionButtons = function (targetSelector) {
|
||||||
// If we want to show one of the grey choose actions state, we can pretend we're in the choose actions state,
|
// If we want to show one of the grey choose actions state, we can pretend we're in the choose actions state,
|
||||||
@@ -134,6 +151,17 @@
|
|||||||
this.render();
|
this.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.selectionStatus = {
|
||||||
|
'default': 'Nothing selected',
|
||||||
|
'selected': numSelected => `${numSelected} selected`,
|
||||||
|
'update': numSelected => {
|
||||||
|
let message = (numSelected > 0) ? this.selectionStatus.selected(numSelected) : this.selectionStatus.default;
|
||||||
|
|
||||||
|
$('.template-list-selected-counter__count').html(message);
|
||||||
|
this.$liveRegionCounter.html(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.templateFolderCheckboxChanged = function() {
|
this.templateFolderCheckboxChanged = function() {
|
||||||
let numSelected = this.countSelectedCheckboxes();
|
let numSelected = this.countSelectedCheckboxes();
|
||||||
|
|
||||||
@@ -147,7 +175,7 @@
|
|||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
$('.template-list-selected-counter-count').html(numSelected);
|
this.selectionStatus.update(numSelected);
|
||||||
|
|
||||||
$('.template-list-selected-counter').toggle(this.hasCheckboxes());
|
$('.template-list-selected-counter').toggle(this.hasCheckboxes());
|
||||||
|
|
||||||
@@ -167,7 +195,7 @@
|
|||||||
|
|
||||||
// detach everything, unless they are the currentState
|
// detach everything, unless they are the currentState
|
||||||
this.states.forEach(
|
this.states.forEach(
|
||||||
state => (state.key === this.currentState ? this.$stickyBottom.append(state.$el) : state.$el.detach())
|
state => (state.key === this.currentState ? this.$liveRegionCounter.before(state.$el) : state.$el.detach())
|
||||||
);
|
);
|
||||||
|
|
||||||
// use dialog mode for states which contain more than one form control
|
// use dialog mode for states which contain more than one form control
|
||||||
@@ -187,7 +215,9 @@
|
|||||||
<button class="button-secondary" value="add-new-template">New template</button>
|
<button class="button-secondary" value="add-new-template">New template</button>
|
||||||
<button class="button-secondary" value="add-new-folder">New folder</button>
|
<button class="button-secondary" value="add-new-folder">New folder</button>
|
||||||
<div class="template-list-selected-counter">
|
<div class="template-list-selected-counter">
|
||||||
Nothing selected
|
<span class="template-list-selected-counter__count" aria-hidden="true">
|
||||||
|
${this.selectionStatus.default}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -198,8 +228,10 @@
|
|||||||
<div class="js-stick-at-bottom-when-scrolling">
|
<div class="js-stick-at-bottom-when-scrolling">
|
||||||
<button class="button-secondary" value="move-to-existing-folder">Move</button>
|
<button class="button-secondary" value="move-to-existing-folder">Move</button>
|
||||||
<button class="button-secondary" value="move-to-new-folder">Add to new folder</button>
|
<button class="button-secondary" value="move-to-new-folder">Add to new folder</button>
|
||||||
<div class="template-list-selected-counter">
|
<div class="template-list-selected-counter" aria-hidden="true">
|
||||||
<span class="template-list-selected-counter-count">1</span> selected
|
<span class="template-list-selected-counter__count" aria-hidden="true">
|
||||||
|
${this.selectionStatus.selected(1)}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -131,10 +131,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-selected-counter {
|
&-selected-counter {
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: $gutter - 1px;
|
|
||||||
color: $secondary-text-colour;
|
color: $secondary-text-colour;
|
||||||
|
margin: $gutter-half 0;
|
||||||
|
|
||||||
|
@include media(tablet) {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: $gutter - 1px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.content-fixed & {
|
.content-fixed & {
|
||||||
right: $gutter-half;
|
right: $gutter-half;
|
||||||
|
|||||||
@@ -36,4 +36,7 @@
|
|||||||
{{ page_footer('Continue', button_name='operation', button_value='add-new-template') }}
|
{{ page_footer('Continue', button_name='operation', button_value='add-new-template') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="selection-counter visuallyhidden" role="status" aria-live="polite">
|
||||||
|
Nothing selected
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user