Commit 4d7d1f55 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Update action-link element to use Shadow DOM v1.

Bug: 837381
Change-Id: I5421657d43646c768def7a5ccf235b9eb483e2e2
Reviewed-on: https://chromium-review.googlesource.com/c/1336548Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608224}
parent 31391ba3
...@@ -27,19 +27,8 @@ ...@@ -27,19 +27,8 @@
// //
// NOTE: <action-link> and document.createElement('action-link') don't work. // NOTE: <action-link> and document.createElement('action-link') don't work.
/** class ActionLink extends HTMLAnchorElement {
* See crbug.com/837381 connectedCallback() {
* @suppress {deprecated}
*
* @constructor
* @extends {HTMLAnchorElement}
*/
var ActionLink = document.registerElement('action-link', {
prototype: {
__proto__: HTMLAnchorElement.prototype,
/** @this {ActionLink} */
createdCallback: function() {
// Action links can start disabled (e.g. <a is="action-link" disabled>). // Action links can start disabled (e.g. <a is="action-link" disabled>).
this.tabIndex = this.disabled ? -1 : 0; this.tabIndex = this.disabled ? -1 : 0;
...@@ -81,36 +70,35 @@ var ActionLink = document.registerElement('action-link', { ...@@ -81,36 +70,35 @@ var ActionLink = document.registerElement('action-link', {
this.addEventListener('blur', function() { this.addEventListener('blur', function() {
this.classList.remove('no-outline'); this.classList.remove('no-outline');
}); });
}, }
/** @type {boolean} */ /** @param {boolean} disabled */
set disabled(disabled) { set disabled(disabled) {
if (disabled) if (disabled)
HTMLAnchorElement.prototype.setAttribute.call(this, 'disabled', ''); HTMLAnchorElement.prototype.setAttribute.call(this, 'disabled', '');
else else
HTMLAnchorElement.prototype.removeAttribute.call(this, 'disabled'); HTMLAnchorElement.prototype.removeAttribute.call(this, 'disabled');
this.tabIndex = disabled ? -1 : 0; this.tabIndex = disabled ? -1 : 0;
}, }
get disabled() { get disabled() {
return this.hasAttribute('disabled'); return this.hasAttribute('disabled');
}, }
/** @override */ /** @override */
setAttribute: function(attr, val) { setAttribute(attr, val) {
if (attr.toLowerCase() == 'disabled') if (attr.toLowerCase() == 'disabled')
this.disabled = true; this.disabled = true;
else else
HTMLAnchorElement.prototype.setAttribute.apply(this, arguments); HTMLAnchorElement.prototype.setAttribute.apply(this, arguments);
}, }
/** @override */ /** @override */
removeAttribute: function(attr) { removeAttribute(attr) {
if (attr.toLowerCase() == 'disabled') if (attr.toLowerCase() == 'disabled')
this.disabled = false; this.disabled = false;
else else
HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments); HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments);
}, }
}, }
customElements.define('action-link', ActionLink, {extends: 'a'});
extends: 'a',
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment