Skip to content

Commit fc78f25

Browse files
committed
feat(esl-trigger): no-target attribute support out of the box, no console warning (default 'disabled' styles)
1 parent 0a403c1 commit fc78f25

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/esl/src/esl-trigger/core/esl-base-trigger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ export abstract class ESLBaseTrigger extends ESLBaseElement {
134134
public updateState(): boolean {
135135
const {active, isTargetActive} = this;
136136

137-
this.toggleAttribute('active', isTargetActive);
137+
this.$$attr('no-target', !this.$target);
138+
this.$$attr('active', isTargetActive);
138139
const clsTarget = ESLTraversingQuery.first(this.activeClassTarget, this) as HTMLElement;
139140
clsTarget && CSSClassUtils.toggle(clsTarget, this.activeClass, isTargetActive);
140141

@@ -159,7 +160,8 @@ export abstract class ESLBaseTrigger extends ESLBaseElement {
159160
/** Handles ESLToggleable state change */
160161
@listen({
161162
event: (that: ESLBaseTrigger) => that.OBSERVED_EVENTS,
162-
target: (that: ESLBaseTrigger) => that.$target
163+
target: (that: ESLBaseTrigger) => that.$target,
164+
condition: (that: ESLBaseTrigger) => !!that.$target
163165
})
164166
protected _onTargetStateChange(originalEvent?: Event): void {
165167
if (!this.updateState()) return;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
esl-trigger {
22
cursor: pointer;
3+
// Default behaviour if no target is specified
4+
&[no-target] {
5+
filter: grayscale(100%);
6+
cursor: not-allowed;
7+
pointer-events: none;
8+
}
39
}

packages/esl/src/esl-trigger/core/esl-trigger.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ export class ESLTrigger extends ESLBaseTrigger {
6262
/** Update `$target` Toggleable from `target` selector */
6363
public updateTargetFromSelector(): void {
6464
if (!this.target) return;
65-
this.$target = ESLTraversingQuery.first(this.target, this) as ESLToggleable;
66-
67-
if (this.$target instanceof ESLToggleablePlaceholder && this.$target.$origin) {
68-
// change target if it is an instance of the placeholder element
69-
this.$target = this.$target.$origin;
70-
}
65+
const $target = ESLTraversingQuery.first(this.target, this) as ESLToggleable | ESLToggleablePlaceholder;
66+
this.$target = ($target instanceof ESLToggleablePlaceholder) ? $target.$origin : $target;
7167
}
7268

7369
/** Check if the event target should be ignored */

0 commit comments

Comments
 (0)