summaryrefslogtreecommitdiffstats
path: root/core/src/jquery/ocdialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/jquery/ocdialog.js')
-rw-r--r--core/src/jquery/ocdialog.js44
1 files changed, 26 insertions, 18 deletions
diff --git a/core/src/jquery/ocdialog.js b/core/src/jquery/ocdialog.js
index 51a1c479e99..c8ea065d3c0 100644
--- a/core/src/jquery/ocdialog.js
+++ b/core/src/jquery/ocdialog.js
@@ -24,6 +24,7 @@
*/
import $ from 'jquery'
+import { isA11yActivation } from '../Util/a11y'
$.widget('oc.ocdialog', {
options: {
@@ -56,6 +57,21 @@ $.widget('oc.ocdialog', {
this.$dialog.append(this.element.detach())
this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog)
+ // Activate the primary button on enter if there is a single input
+ if (self.element.find('input').length === 1) {
+ const $input = self.element.find('input')
+ $input.on('keydown', function(event) {
+ if (isA11yActivation(event)) {
+ if (self.$buttonrow) {
+ const $button = self.$buttonrow.find('button.primary')
+ if ($button && !$button.prop('disabled')) {
+ $button.click()
+ }
+ }
+ }
+ })
+ }
+
this.$dialog.css({
display: 'inline-block',
position: 'fixed',
@@ -92,18 +108,6 @@ $.widget('oc.ocdialog', {
event.preventDefault()
return false
}
- // If no button is selected we trigger the primary
- if (
- self.$buttonrow
- && self.$buttonrow.find($(event.target)).length === 0
- ) {
- const $button = self.$buttonrow.find('button.primary')
- if ($button && !$button.prop('disabled')) {
- $button.trigger('click')
- }
- } else if (self.$buttonrow) {
- $(event.target).trigger('click')
- }
return false
}
})
@@ -153,8 +157,10 @@ $.widget('oc.ocdialog', {
self.$defaultButton = $button
}
self.$buttonrow.append($button)
- $button.click(function() {
- val.click.apply(self.element[0], arguments)
+ $button.on('click keydown', function(event) {
+ if (isA11yActivation(event)) {
+ val.click.apply(self.element[0], arguments)
+ }
})
})
this.$buttonrow.find('button')
@@ -171,11 +177,13 @@ $.widget('oc.ocdialog', {
break
case 'closeButton':
if (value) {
- const $closeButton = $('<a class="oc-dialog-close"></a>')
+ const $closeButton = $('<a class="oc-dialog-close" tabindex="0"></a>')
this.$dialog.prepend($closeButton)
- $closeButton.on('click', function() {
- self.options.closeCallback && self.options.closeCallback()
- self.close()
+ $closeButton.on('click keydown', function(event) {
+ if (isA11yActivation(event)) {
+ self.options.closeCallback && self.options.closeCallback()
+ self.close()
+ }
})
} else {
this.$dialog.find('.oc-dialog-close').remove()