@spectrum-web-components/shared
Advanced tools
Comparing version 0.4.6 to 0.4.7
@@ -6,2 +6,6 @@ # Change Log | ||
## [0.4.7](https://github.com/adobe/spectrum-web-components/compare/@spectrum-web-components/shared@0.4.6...@spectrum-web-components/shared@0.4.7) (2020-06-08) | ||
**Note:** Version bump only for package @spectrum-web-components/shared | ||
## [0.4.6](https://github.com/adobe/spectrum-web-components/compare/@spectrum-web-components/shared@0.4.5...@spectrum-web-components/shared@0.4.6) (2020-04-16) | ||
@@ -8,0 +12,0 @@ |
@@ -6,3 +6,3 @@ declare global { | ||
} | ||
declare type Constructor<T = object> = { | ||
declare type Constructor<T = Record<string, unknown>> = { | ||
new (...args: any[]): T; | ||
@@ -9,0 +9,0 @@ prototype: T; |
@@ -22,131 +22,135 @@ import { __decorate } from "tslib"; | ||
*/ | ||
export class Focusable extends FocusVisiblePolyfillMixin(LitElement) { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* Disable this control. It will not receive focus or events | ||
*/ | ||
this.disabled = false; | ||
/** | ||
* When this control is rendered, focus it automatically | ||
*/ | ||
this.autofocus = false; | ||
/** | ||
* The tab index to apply to this control. See general documentation about | ||
* the tabindex HTML property | ||
*/ | ||
this.tabIndex = 0; | ||
this.isShiftTabbing = false; | ||
this.newTabindex = 0; | ||
this.oldTabindex = 0; | ||
} | ||
static get styles() { | ||
return [focusableStyles]; | ||
} | ||
get focusElement() { | ||
throw new Error('Must implement focusElement getter!'); | ||
} | ||
focus() { | ||
if (this.disabled) { | ||
return; | ||
let Focusable = /** @class */ (() => { | ||
class Focusable extends FocusVisiblePolyfillMixin(LitElement) { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* Disable this control. It will not receive focus or events | ||
*/ | ||
this.disabled = false; | ||
/** | ||
* When this control is rendered, focus it automatically | ||
*/ | ||
this.autofocus = false; | ||
/** | ||
* The tab index to apply to this control. See general documentation about | ||
* the tabindex HTML property | ||
*/ | ||
this.tabIndex = 0; | ||
this.isShiftTabbing = false; | ||
this.newTabindex = 0; | ||
this.oldTabindex = 0; | ||
} | ||
this.focusElement.focus(); | ||
} | ||
blur() { | ||
this.focusElement.blur(); | ||
} | ||
manageAutoFocus() { | ||
if (this.autofocus) { | ||
/* Trick :focus-visible polyfill into thinking keyboard based focus */ | ||
this.dispatchEvent(new KeyboardEvent('keydown', { | ||
code: 'Tab', | ||
})); | ||
this.focus(); | ||
static get styles() { | ||
return [focusableStyles]; | ||
} | ||
} | ||
firstUpdated(changes) { | ||
super.firstUpdated(changes); | ||
this.manageAutoFocus(); | ||
this.manageFocusIn(); | ||
this.manageShiftTab(); | ||
} | ||
manageFocusIn() { | ||
this.addEventListener('focusin', (event) => { | ||
if (event.composedPath()[0] === this) { | ||
this.handleFocus(); | ||
get focusElement() { | ||
throw new Error('Must implement focusElement getter!'); | ||
} | ||
focus() { | ||
if (this.disabled) { | ||
return; | ||
} | ||
}); | ||
} | ||
manageShiftTab() { | ||
this.addEventListener('keydown', (event) => { | ||
if (!event.defaultPrevented && | ||
event.shiftKey && | ||
event.code === 'Tab') { | ||
this.isShiftTabbing = true; | ||
HTMLElement.prototype.focus.apply(this); | ||
setTimeout(() => (this.isShiftTabbing = false), 0); | ||
} | ||
}); | ||
} | ||
update(changedProperties) { | ||
if (changedProperties.has('disabled')) { | ||
this.handleDisabledChanged(this.disabled, changedProperties.get('disabled')); | ||
this.focusElement.focus(); | ||
} | ||
if (changedProperties.has('tabIndex')) { | ||
// save value of tabindex, as it can be overridden to | ||
// undefined in case if the element is disabled | ||
this.newTabindex = this.tabIndex; | ||
this.handleTabIndexChanged(this.tabIndex); | ||
blur() { | ||
this.focusElement.blur(); | ||
} | ||
super.update(changedProperties); | ||
} | ||
updated(changedProperties) { | ||
super.updated(changedProperties); | ||
if (changedProperties.has('disabled')) { | ||
this.focusElement.disabled = this.disabled; | ||
if (this.disabled) { | ||
this.blur(); | ||
manageAutoFocus() { | ||
if (this.autofocus) { | ||
/* Trick :focus-visible polyfill into thinking keyboard based focus */ | ||
this.dispatchEvent(new KeyboardEvent('keydown', { | ||
code: 'Tab', | ||
})); | ||
this.focus(); | ||
} | ||
} | ||
if (changedProperties.has('tabIndex') && | ||
this.newTabindex !== undefined) { | ||
this.focusElement.tabIndex = this.newTabindex; | ||
this.newTabindex = undefined; | ||
firstUpdated(changes) { | ||
super.firstUpdated(changes); | ||
this.manageAutoFocus(); | ||
this.manageFocusIn(); | ||
this.manageShiftTab(); | ||
} | ||
} | ||
handleFocus() { | ||
if (this.isShiftTabbing) { | ||
return; | ||
manageFocusIn() { | ||
this.addEventListener('focusin', (event) => { | ||
if (event.composedPath()[0] === this) { | ||
this.handleFocus(); | ||
} | ||
}); | ||
} | ||
this.focusElement.focus(); | ||
} | ||
handleDisabledChanged(disabled, oldDisabled) { | ||
if (disabled) { | ||
this.oldTabindex = this.tabIndex; | ||
this.tabIndex = -1; | ||
this.setAttribute('aria-disabled', 'true'); | ||
manageShiftTab() { | ||
this.addEventListener('keydown', (event) => { | ||
if (!event.defaultPrevented && | ||
event.shiftKey && | ||
event.code === 'Tab') { | ||
this.isShiftTabbing = true; | ||
HTMLElement.prototype.focus.apply(this); | ||
setTimeout(() => (this.isShiftTabbing = false), 0); | ||
} | ||
}); | ||
} | ||
else if (oldDisabled) { | ||
this.tabIndex = this.oldTabindex; | ||
this.removeAttribute('aria-disabled'); | ||
update(changedProperties) { | ||
if (changedProperties.has('disabled')) { | ||
this.handleDisabledChanged(this.disabled, changedProperties.get('disabled')); | ||
} | ||
if (changedProperties.has('tabIndex')) { | ||
// save value of tabindex, as it can be overridden to | ||
// undefined in case if the element is disabled | ||
this.newTabindex = this.tabIndex; | ||
this.handleTabIndexChanged(this.tabIndex); | ||
} | ||
super.update(changedProperties); | ||
} | ||
} | ||
handleTabIndexChanged(tabindex) { | ||
if (this.disabled && tabindex) { | ||
if (this.tabIndex !== -1) { | ||
updated(changedProperties) { | ||
super.updated(changedProperties); | ||
if (changedProperties.has('disabled')) { | ||
this.focusElement.disabled = this.disabled; | ||
if (this.disabled) { | ||
this.blur(); | ||
} | ||
} | ||
if (changedProperties.has('tabIndex') && | ||
this.newTabindex !== undefined) { | ||
this.focusElement.tabIndex = this.newTabindex; | ||
this.newTabindex = undefined; | ||
} | ||
} | ||
handleFocus() { | ||
if (this.isShiftTabbing) { | ||
return; | ||
} | ||
this.focusElement.focus(); | ||
} | ||
handleDisabledChanged(disabled, oldDisabled) { | ||
if (disabled) { | ||
this.oldTabindex = this.tabIndex; | ||
this.tabIndex = -1; | ||
this.setAttribute('aria-disabled', 'true'); | ||
} | ||
this.tabIndex = -1; | ||
else if (oldDisabled) { | ||
this.tabIndex = this.oldTabindex; | ||
this.removeAttribute('aria-disabled'); | ||
} | ||
} | ||
handleTabIndexChanged(tabindex) { | ||
if (this.disabled && tabindex) { | ||
if (this.tabIndex !== -1) { | ||
this.oldTabindex = this.tabIndex; | ||
} | ||
this.tabIndex = -1; | ||
} | ||
} | ||
} | ||
} | ||
__decorate([ | ||
property({ type: Boolean, reflect: true }) | ||
], Focusable.prototype, "disabled", void 0); | ||
__decorate([ | ||
property({ type: Boolean }) | ||
], Focusable.prototype, "autofocus", void 0); | ||
__decorate([ | ||
property({ type: Number, reflect: true }) | ||
], Focusable.prototype, "tabIndex", void 0); | ||
__decorate([ | ||
property({ type: Boolean, reflect: true }) | ||
], Focusable.prototype, "disabled", void 0); | ||
__decorate([ | ||
property({ type: Boolean }) | ||
], Focusable.prototype, "autofocus", void 0); | ||
__decorate([ | ||
property({ type: Number, reflect: true }) | ||
], Focusable.prototype, "tabIndex", void 0); | ||
return Focusable; | ||
})(); | ||
export { Focusable }; | ||
//# sourceMappingURL=focusable.js.map |
import { UpdatingElement, TemplateResult } from 'lit-element'; | ||
declare type Constructor<T = object> = { | ||
declare type Constructor<T = Record<string, unknown>> = { | ||
new (...args: any[]): T; | ||
@@ -4,0 +4,0 @@ prototype: T; |
@@ -16,8 +16,9 @@ import { __decorate } from "tslib"; | ||
export function LikeAnchor(constructor) { | ||
class LikeAnchorElement extends constructor { | ||
renderAnchor({ id, | ||
// prettier-ignore | ||
anchorContent = html `<slot></slot>` }) { | ||
let LikeAnchorElement = /** @class */ (() => { | ||
class LikeAnchorElement extends constructor { | ||
renderAnchor({ id, | ||
// prettier-ignore | ||
return html `<a | ||
anchorContent = html `<slot></slot>` }) { | ||
// prettier-ignore | ||
return html `<a | ||
id=${id} | ||
@@ -29,18 +30,20 @@ href=${ifDefined(this.href)} | ||
>${anchorContent}</a>`; | ||
} | ||
} | ||
} | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "download", void 0); | ||
__decorate([ | ||
property() | ||
], LikeAnchorElement.prototype, "label", void 0); | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "href", void 0); | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "target", void 0); | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "download", void 0); | ||
__decorate([ | ||
property() | ||
], LikeAnchorElement.prototype, "label", void 0); | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "href", void 0); | ||
__decorate([ | ||
property({ reflect: true }) | ||
], LikeAnchorElement.prototype, "target", void 0); | ||
return LikeAnchorElement; | ||
})(); | ||
return LikeAnchorElement; | ||
} | ||
//# sourceMappingURL=like-anchor.js.map |
import { UpdatingElement } from 'lit-element'; | ||
declare type Constructor<T = object> = { | ||
declare type Constructor<T = Record<string, unknown>> = { | ||
new (...args: any[]): T; | ||
@@ -4,0 +4,0 @@ prototype: T; |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"description": "", | ||
@@ -44,5 +44,5 @@ "main": "lib/index.js", | ||
"focus-visible": "^5.0.2", | ||
"tslib": "^1.10.0" | ||
"tslib": "^2.0.0" | ||
}, | ||
"gitHead": "c8a769e3b24974f722054bc121f9a896d66e0bf1" | ||
"gitHead": "16b57d15356859cee73278cdf796274e3245320b" | ||
} |
@@ -19,3 +19,3 @@ /* | ||
type Constructor<T = object> = { | ||
type Constructor<T = Record<string, unknown>> = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -22,0 +22,0 @@ new (...args: any[]): T; |
@@ -15,3 +15,3 @@ /* | ||
type Constructor<T = object> = { | ||
type Constructor<T = Record<string, unknown>> = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -18,0 +18,0 @@ new (...args: any[]): T; |
@@ -18,3 +18,3 @@ /* | ||
type Constructor<T = object> = { | ||
type Constructor<T = Record<string, unknown>> = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -21,0 +21,0 @@ new (...args: any[]): T; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91255
998
+ Addedtslib@2.7.0(transitive)
- Removedtslib@1.14.1(transitive)
Updatedtslib@^2.0.0