Skip to content

Commit

Permalink
Fix/reuse UUID missing parent callback disabled property (#2090)
Browse files Browse the repository at this point in the history
* refactor: reuse uuid function from the core

* fix: invoke parent class callback

* fix: do not run disabled property reflection unless it was part of the changeset
  • Loading branch information
ilinsky authored Nov 27, 2023
1 parent 322b065 commit bf78222
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-months-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

do not run disabled property reflection unless it was part of the changeset in LionSwitchButton
5 changes: 5 additions & 0 deletions .changeset/soft-wombats-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

reuse uuid function from the core in LionButton and LionInputDatepicker
5 changes: 5 additions & 0 deletions .changeset/sweet-zebras-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

invoke parent class updated callback in LionCollapsible, LionDrawer and LionSwitchButton
4 changes: 2 additions & 2 deletions packages/ui/components/button/src/LionButton.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html, LitElement, css } from 'lit';
import { browserDetection, DisabledWithTabIndexMixin } from '@lion/ui/core.js';
import { browserDetection, DisabledWithTabIndexMixin, uuid } from '@lion/ui/core.js';

const isKeyboardClickEvent = (/** @type {KeyboardEvent} */ e) => e.key === ' ' || e.key === 'Enter';
const isSpaceKeyboardClickEvent = (/** @type {KeyboardEvent} */ e) => e.key === ' ';
Expand Down Expand Up @@ -124,7 +124,7 @@ export class LionButton extends DisabledWithTabIndexMixin(LitElement) {
this.type = 'button';
this.active = false;

this._buttonId = `button-${Math.random().toString(36).substr(2, 10)}`;
this._buttonId = uuid('button');
if (browserDetection.isIE11) {
this.updateComplete.then(() => {
if (!this.hasAttribute('aria-labelledby')) {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/collapsible/src/LionCollapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class LionCollapsible extends LitElement {
* @param {import('lit').PropertyValues } changedProperties
*/
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('opened')) {
this.__openedChanged();
}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/drawer/src/LionDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class LionDrawer extends LionCollapsible {
* @param {import('lit').PropertyValues } changedProperties
*/
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('opened')) {
this._openedChanged();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import { LionCalendar } from '@lion/ui/calendar.js';
import { uuid } from '@lion/ui/core.js';
import { ScopedElementsMixin } from '@open-wc/scoped-elements';
import { html, css } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
Expand Down Expand Up @@ -149,7 +150,7 @@ export class LionInputDatepicker extends ScopedElementsMixin(
constructor() {
super();
/** @private */
this.__invokerId = this.__createUniqueIdForA11y();
this.__invokerId = uuid(this.localName);
/** @protected */
this._calendarInvokerSlot = 'suffix';

Expand All @@ -169,11 +170,6 @@ export class LionInputDatepicker extends ScopedElementsMixin(
this._onCalendarUserSelectedChanged = this._onCalendarUserSelectedChanged.bind(this);
}

/** @private */
__createUniqueIdForA11y() {
return `${this.localName}-${Math.random().toString(36).substr(2, 10)}`;
}

/**
* @param {string} [name]
* @param {unknown} [oldValue]
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/components/switch/src/LionSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
/** @param {import('lit').PropertyValues } changedProperties */
updated(changedProperties) {
super.updated(changedProperties);
this._syncButtonSwitch();
if (changedProperties.has('disabled')) {
this._syncButtonSwitch();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/switch/src/LionSwitchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {

/** @param {import('lit').PropertyValues } changedProperties */
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('disabled')) {
this.setAttribute('aria-disabled', `${this.disabled}`); // create mixin if we need it in more places
}
Expand Down

0 comments on commit bf78222

Please sign in to comment.