11<script setup lang="ts">
22import { storeToRefs } from ' pinia'
3- import { computed } from ' vue'
3+ import { computed , ref , onMounted , onUnmounted } from ' vue'
44import { useFacetStore } from ' ../stores/facets'
55import { useSessionStore } from ' ../stores/session'
66import { useSearchStore } from ' ../stores/search'
@@ -16,6 +16,31 @@ const { facets } = storeToRefs(useFacetStore())
1616const { isAdmin } = storeToRefs (useSessionStore ())
1717
1818const search = useSearchStore ()
19+ const facetsOpen = ref (false )
20+ const isMobile = ref (window .innerWidth <= 700 )
21+
22+ function toggleFacets() {
23+ facetsOpen .value = ! facetsOpen .value
24+ }
25+
26+ function handleWindowResize() {
27+ isMobile .value = window .innerWidth <= 700
28+ if (isMobile .value ) {
29+ facetsOpen .value = false
30+ }
31+ else {
32+ facetsOpen .value = true
33+ }
34+ }
35+
36+ onMounted (() => {
37+ window .addEventListener (' resize' , handleWindowResize )
38+ handleWindowResize ()
39+ })
40+ onUnmounted (() => {
41+ window .removeEventListener (' resize' , handleWindowResize )
42+ })
43+
1944const liveMessage = computed (() => {
2045 const parts: string [] = []
2146 for (const facetName of search .activeFacetNames ) {
@@ -33,12 +58,24 @@ const liveMessage = computed(() => {
3358<template >
3459 <div class =" galc-facets" >
3560 <TermDeselection id-prefix =" facets" />
36- <input id =" show-facets" type =" checkbox" >
37- <label class =" show-facets-label" for =" show-facets" >
61+
62+ <button
63+ v-if =" isMobile"
64+ class =" show-facets-button"
65+ type =" button"
66+ @click =" toggleFacets"
67+ :aria-expanded =" facetsOpen.toString()"
68+ aria-controls =" facet-form"
69+ >
3870 Options
39- <img alt =" Options" :src =" filter" class =" show-facets-icon" >
40- </label >
41- <form class =" galc-facet-form" >
71+ <img alt =" " :src =" filter" class =" show-facets-icon" >
72+ </button >
73+
74+ <form
75+ id =" facet-form"
76+ class =" galc-facet-form"
77+ v-show =" facetsOpen || !isMobile"
78+ >
4279 <Suppressed v-if =" isAdmin" />
4380 <InternalFields v-if =" isAdmin" />
4481 <Facet
@@ -50,134 +87,50 @@ const liveMessage = computed(() => {
5087 </form >
5188
5289 <!-- Accessible live region -->
53- <span class =" sr-only" aria-live =" polite" aria-atomic =" true" >{{ liveMessage }}</span >
54-
90+ <span class =" sr-only" aria-live =" polite" aria-atomic =" true" >
91+ {{ liveMessage }}
92+ </span >
5593 </div >
5694</template >
5795
5896<style lang="scss">
59- div .galc-facets {
60-
61- input #show-facets {
62- display : none ;
63- }
64-
65- @media only screen and (min-width : 700px ) {
66- margin-right : 1em ;
67-
68- // TODO: less hacky way to place this differently on desktop and mobile
69- .galc-term-deselection {
70- display : none ;
71- }
72-
73- label .show-facets-label {
74- display : none ;
75- }
76-
77- form .galc-facet-form {
78- width : 150px ;
97+ .show-facets-button {
98+ display : none ;
99+ }
100+ @media only screen and (max-width : 700px ) {
101+ .show-facets-button {
102+ display : block ;
103+ font-size : 1rem ;
104+ line-height : 1.75rem ;
105+ font-weight : normal ;
106+ color : white ;
107+ background-color : #46535e ;
108+ padding : 2px 8px ;
109+ margin : 6px 16px 6px 0 ;
110+ width : fit-content ;
111+ cursor : pointer ;
112+ border : none ;
113+ border-radius : 4px ;
114+
115+ img .show-facets-icon {
116+ height : 0.9rem ;
117+ width : 0.9rem ;
118+ filter : invert (100% );
119+ display : inline ;
120+ margin-bottom : 4px ;
121+ margin-left : 4px ;
79122 }
80123 }
81-
82- @media only screen and (max-width : 700px ) {
83- input #show-facets {
84- ~ form .galc-facet-form {
85- display : none ;
86- }
87-
88- & :checked ~ form .galc-facet-form {
89- display : grid ;
90- }
91- }
92-
93- label .show-facets-label {
94- display : block ;
95- font-size : 1rem ;
96- line-height : 1.75rem ;
97- font-weight : normal ;
98- color : white ;
99- background-color : #46535e ;
100- padding : 2px 8px ;
101- margin : 6px 16px 6px 0 ;
102- width : fit-content ;
103- cursor : pointer ;
104-
105- img .show-facets-icon {
106- height : 0.9rem ;
107- width : 0.9rem ;
108- filter : invert (100% );
109- display : inline ;
110- margin-bottom : -2px ;
111- margin-left : 4px ;
112- }
113- }
114- }
115-
116- form .galc-facet-form {
117- display : grid ;
118- grid-template-columns : 1fr ;
119- align-items : center ;
120- justify-items : start ;
121-
122- // TODO: rationalize these measurements
123- column-gap : 0.5rem ;
124- row-gap : 0 ;
125- margin-right : 2rem ;
126-
127- .galc-facet-title {
128- white-space : nowrap ;
129- grid-column : 1 / 4 ;
130- margin-bottom : 0.25em ;
131- }
132-
133- > fieldset {
134- padding-bottom : 0 ;
135- width : 100% ;
136-
137- details {
138- summary {
139- grid-column : 1 / 4 ;
140- }
141-
142- input {
143- grid-column : 1 ;
144- }
145-
146- label {
147- grid-column : 2 / 4 ;
148- }
149-
150- fieldset {
151-
152- input {
153- grid-column : 1 ;
154- }
155-
156- label {
157- grid-column : 2 / 4 ;
158- }
159- }
160- }
161-
162- & :not (:first-of-type ) {
163- summary {
164- margin-top : 0.25em ;
165- }
166- }
167- }
168- }
169-
170- .sr-only {
171- position : absolute ;
172- width : 1px ;
173- height : 1px ;
174- padding : 0 ;
175- margin : -1px ;
176- overflow : hidden ;
177- clip : rect (0 , 0 , 0 , 0 );
178- white-space : nowrap ;
179- border-width : 0 ;
180- }
181- }
182-
183- </style >
124+ }
125+ .sr-only {
126+ position : absolute ;
127+ width : 1px ;
128+ height : 1px ;
129+ padding : 0 ;
130+ margin : -1px ;
131+ overflow : hidden ;
132+ clip : rect (0 , 0 , 0 , 0 );
133+ white-space : nowrap ;
134+ border-width : 0 ;
135+ }
136+ </style >
0 commit comments