Skip to content

Commit

Permalink
do not collapse card when on "Search" and "Select"
Browse files Browse the repository at this point in the history
  • Loading branch information
undergroundwires committed Jul 19, 2020
1 parent 1d5225d commit dd7e141
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/presentation/Scripts/Cards/CardList.vue
Expand Up @@ -20,6 +20,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator';
import CardListItem from './CardListItem.vue';
import { StatefulVue } from '@/presentation/StatefulVue';
import { ICategory } from '@/domain/ICategory';
import { hasDirective } from './NonCollapsingDirective';
@Component({
components: {
Expand All @@ -33,7 +34,10 @@ export default class CardList extends StatefulVue {
public async mounted() {
const state = await this.getCurrentStateAsync();
this.setCategories(state.app.actions);
this.onOutsideOfActiveCardClicked(() => {
this.onOutsideOfActiveCardClicked((element) => {
if (hasDirective(element)) {
return;
}
this.activeCategoryId = null;
});
}
Expand All @@ -46,14 +50,14 @@ export default class CardList extends StatefulVue {
this.categoryIds = categories.map((category) => category.id);
}
private onOutsideOfActiveCardClicked(callback) {
private onOutsideOfActiveCardClicked(callback: (clickedElement: Element) => void) {
const outsideClickListener = (event) => {
if (!this.activeCategoryId) {
return;
}
const element = document.querySelector(`[data-category="${this.activeCategoryId}"]`);
if (element && !element.contains(event.target)) {
callback();
callback(event.target);
}
};
document.addEventListener('click', outsideClickListener);
Expand Down
17 changes: 17 additions & 0 deletions src/presentation/Scripts/Cards/NonCollapsingDirective.ts
@@ -0,0 +1,17 @@
import { DirectiveOptions } from 'vue';

const attributeName = 'data-interactionDoesNotCollapse';

export function hasDirective(el: Element): boolean {
if (el.hasAttribute(attributeName)) {
return true;
}
const parent = el.closest(`[${attributeName}]`);
return !!parent;
}

export const NonCollapsing: DirectiveOptions = {
inserted(el: HTMLElement) {
el.setAttribute(attributeName, '');
},
};
6 changes: 5 additions & 1 deletion src/presentation/Scripts/Selector/SelectableOption.vue
@@ -1,14 +1,18 @@
<template>
<span
v-bind:class="{ 'disabled': enabled, 'enabled': !enabled}"
v-non-collapsing
@click="onClicked()">{{label}}</span>
</template>

<script lang="ts">
import { Component, Prop, Vue, Emit } from 'vue-property-decorator';
import { StatefulVue } from '@/presentation/StatefulVue';
import { NonCollapsing } from '@/presentation/Scripts/Cards/NonCollapsingDirective';
@Component
@Component({
directives: { NonCollapsing },
})
export default class SelectableOption extends StatefulVue {
@Prop() public enabled: boolean;
@Prop() public label: string;
Expand Down
11 changes: 8 additions & 3 deletions src/presentation/TheSearchBar.vue
@@ -1,6 +1,7 @@
<template>
<div class="search">
<input type="search" class="searchTerm" :placeholder="searchPlaceHolder"
<div class="search" v-non-collapsing>
<input type="search" class="searchTerm"
:placeholder="searchPlaceHolder"
@input="updateFilterAsync($event.target.value)" >
<div class="iconWrapper">
<font-awesome-icon :icon="['fas', 'search']" />
Expand All @@ -11,8 +12,12 @@
<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import { StatefulVue } from './StatefulVue';
import { NonCollapsing } from '@/presentation/Scripts/Cards/NonCollapsingDirective';
@Component
@Component( {
directives: { NonCollapsing },
},
)
export default class TheSearchBar extends StatefulVue {
public searchPlaceHolder = 'Search';
Expand Down

0 comments on commit dd7e141

Please sign in to comment.