Skip to content

Commit 2502f81

Browse files
committed
feat: when the user adds a css class to an element, it needs to be selected and unselect the other classes
1 parent 02ae65f commit 2502f81

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/components/compound-selector.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ export default class CompoundSelectorComponent extends StylableElement {
153153
)
154154
}
155155

156+
// When a class is activated, deactivate all other classes (but keep ID and TAG active)
157+
const isNewlyActivatedClass = event.detail.type === SimpleSelectorType.CLASS
158+
&& event.detail.active
159+
&& (!oldValue || !oldValue.active || !isSameSelector(oldValue, event.detail))
160+
161+
if (isNewlyActivatedClass) {
162+
updatedSelectors = updatedSelectors.map(selector =>
163+
selector.type === SimpleSelectorType.CLASS && !isSameSelector(selector, event.detail)
164+
? { ...selector, active: false }
165+
: selector
166+
)
167+
}
168+
156169
// When all selectors are deactivated but pseudo class exists, activate ID selector
157170
const hasActiveSelectors = updatedSelectors.some(selector => selector.active)
158171
if (!hasActiveSelectors && this.value!.pseudoClass) {

0 commit comments

Comments
 (0)