Skip to content

Commit 5a9ee51

Browse files
muller39Lenajava1
andauthored
feat(VCST-4103): navigation in filters-popup-sidebar (#2024)
## Description ## References ### Jira-link: https://virtocommerce.atlassian.net/browse/VCST-4103 ### Artifact URL: https://vc3prerelease.blob.core.windows.net/packages/vc-theme-b2b-vue-2.34.0-pr-2024-f1e7-f1e7cc1b.zip --------- Co-authored-by: Elena Mutykova <[email protected]>
1 parent 5ff2d7d commit 5a9ee51

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

client-app/pages/product.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ const {
235235
isFiltersSidebarVisible,
236236
productsFilters,
237237
applyFilters: _applyFilters,
238-
hideFiltersSidebar,
238+
hideFiltersSidebar: _hideFiltersSidebar,
239239
resetFacetFilters: _resetFacetFilters,
240240
showFiltersSidebar,
241241
} = useProducts({
@@ -403,6 +403,14 @@ async function resetFacetFilters(): Promise<void> {
403403
void applyFilters(productsFilters.value);
404404
}
405405
406+
function hideFiltersSidebar(): void {
407+
_hideFiltersSidebar();
408+
const variationsFiltersButton = document.getElementById(`${productId.value}-variations-filters-button`);
409+
if (variationsFiltersButton) {
410+
variationsFiltersButton.focus();
411+
}
412+
}
413+
406414
function checkLineItemId() {
407415
const cartItems = cart.value?.items;
408416
return cartItems?.some((item) => item.id === lineItemId);

client-app/shared/catalog/components/category/filters-popup-sidebar.vue

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
>
88
<ProductsFilters
99
v-if="localFilters"
10+
:id="productsFiltersId"
1011
:keyword="keywordQueryParam"
1112
:filters="localFilters"
1213
:loading="loading || facetsLoading"
@@ -96,9 +97,10 @@
9697
<script setup lang="ts">
9798
import cloneDeep from "lodash/cloneDeep";
9899
import isEqual from "lodash/isEqual";
99-
import { watch, ref, computed } from "vue";
100+
import { watch, ref, computed, nextTick, onMounted, onUnmounted } from "vue";
100101
import { usePurchasedBefore } from "@/shared/catalog/composables";
101102
import { useModal } from "@/shared/modal";
103+
import { useComponentId } from "@/ui-kit/composables";
102104
import type { SearchProductFilterResult } from "@/core/api/graphql/types.ts";
103105
import type { ProductsFiltersType } from "@/shared/catalog";
104106
import ProductsFilters from "@/shared/catalog/components/products-filters.vue";
@@ -124,6 +126,8 @@ interface IProps {
124126
isExistSelectedFacets: boolean;
125127
}
126128
129+
const productsFiltersId = useComponentId("products-filters");
130+
127131
const localFilters = ref<ProductsFiltersType>({
128132
filters: [],
129133
facets: [],
@@ -159,9 +163,11 @@ watch(
159163
160164
watch(
161165
() => props.isVisible,
162-
(visible) => {
166+
async (visible) => {
163167
if (visible) {
164168
beforeChangeFilterState.value = cloneDeep(props.popupSidebarFilters);
169+
await nextTick();
170+
focusFirstElement();
165171
}
166172
},
167173
);
@@ -196,6 +202,22 @@ function onApply() {
196202
emit("hidePopupSidebar");
197203
}
198204
205+
function focusFirstElement() {
206+
const firstFocusableElement = document
207+
.getElementById(productsFiltersId)
208+
?.querySelector("input:not(:disabled), button:not(:disabled)");
209+
if (firstFocusableElement && firstFocusableElement instanceof HTMLElement) {
210+
firstFocusableElement.focus();
211+
}
212+
}
213+
214+
function handleKeydown(event: KeyboardEvent) {
215+
if (event.key === "Escape" && props.isVisible) {
216+
event.preventDefault();
217+
emit("hidePopupSidebar");
218+
}
219+
}
220+
199221
const { openModal } = useModal();
200222
function openBranchesModal() {
201223
openModal({
@@ -213,6 +235,14 @@ function openBranchesModal() {
213235
},
214236
});
215237
}
238+
239+
onMounted(() => {
240+
document.addEventListener("keydown", handleKeydown);
241+
});
242+
243+
onUnmounted(() => {
244+
document.removeEventListener("keydown", handleKeydown);
245+
});
216246
</script>
217247

218248
<style lang="scss">

client-app/shared/catalog/components/product/variations.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/>
4141
</div>
4242

43-
<VcButton variant="outline" @click="$emit('showFilters')">
43+
<VcButton :id="`${productId}-variations-filters-button`" variant="outline" @click="$emit('showFilters')">
4444
{{ $t("common.buttons.filters") }}
4545
</VcButton>
4646
</div>

0 commit comments

Comments
 (0)