Files
gerrit/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label.js
Kasper Nilsson 76067cdd13 Add various aria labels and a11y features to PG
1) Added aria-label to account-dropdown avatar
2) Added aria-label to change-star
3) Added computed aria-label to issue number
4) No action required
5) Added aria-label to remove reviewer button
6) No action required
7) Added aria-label to checkboxes
8) Added computed aria-label to file status marker
9) Added aria-label to file line +- markers
10) Solved by agable@
11) No longer an issue with unrelated changes to comments

Feature: Issue 4279
Change-Id: If735f369bae5d1e867c664a4d55d11664bbc5196
2017-01-31 11:09:27 -08:00

114 lines
2.7 KiB
JavaScript

// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
(function() {
'use strict';
Polymer({
is: 'gr-editable-label',
/**
* Fired when the value is changed.
*
* @event changed
*/
properties: {
editing: {
type: Boolean,
value: false,
},
value: {
type: String,
notify: true,
value: null,
observer: '_updateTitle',
},
placeholder: {
type: String,
value: null,
},
readOnly: {
type: Boolean,
value: false,
},
_inputText: String,
},
hostAttributes: {
tabindex: '0',
},
_usePlaceholder: function(value, placeholder) {
return (!value || !value.length) && placeholder;
},
_computeLabel: function(value, placeholder) {
if (this._usePlaceholder(value, placeholder)) {
return placeholder;
}
return value;
},
_open: function() {
if (this.readOnly || this.editing) { return; }
this._inputText = this.value;
this.editing = true;
this.async(function() {
this.$.input.focus();
this.$.input.setSelectionRange(0, this.$.input.value.length);
});
},
_save: function() {
if (!this.editing) { return; }
this.value = this._inputText;
this.editing = false;
this.fire('changed', this.value);
},
_cancel: function() {
if (!this.editing) { return; }
this.editing = false;
this._inputText = this.value;
},
_handleInputKeydown: function(e) {
if (e.keyCode === 13) { // Enter key
e.preventDefault();
this._save();
} else if (e.keyCode === 27) { // Escape key
e.preventDefault();
this._cancel();
}
},
_computeLabelClass: function(readOnly, value, placeholder) {
var classes = [];
if (!readOnly) { classes.push('editable'); }
if (this._usePlaceholder(value, placeholder)) {
classes.push('placeholder');
}
return classes.join(' ');
},
_updateTitle: function(value) {
this.setAttribute('title', (value && value.length) ? value : null);
},
});
})();