77 >
88 <ProductsFilters
99 v-if =" localFilters"
10+ :id =" productsFiltersId"
1011 :keyword =" keywordQueryParam"
1112 :filters =" localFilters"
1213 :loading =" loading || facetsLoading"
9697<script setup lang="ts">
9798import cloneDeep from " lodash/cloneDeep" ;
9899import isEqual from " lodash/isEqual" ;
99- import { watch , ref , computed } from " vue" ;
100+ import { watch , ref , computed , nextTick , onMounted , onUnmounted } from " vue" ;
100101import { usePurchasedBefore } from " @/shared/catalog/composables" ;
101102import { useModal } from " @/shared/modal" ;
103+ import { useComponentId } from " @/ui-kit/composables" ;
102104import type { SearchProductFilterResult } from " @/core/api/graphql/types.ts" ;
103105import type { ProductsFiltersType } from " @/shared/catalog" ;
104106import 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+
127131const localFilters = ref <ProductsFiltersType >({
128132 filters: [],
129133 facets: [],
@@ -159,9 +163,11 @@ watch(
159163
160164watch (
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+
199221const { openModal } = useModal ();
200222function 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">
0 commit comments