ReviewOS

also looking at this

stacks/analyticshq

fix(dashboard): close the date picker on a click outside it

#56
Merged glennmichael123 wants to merge fix/date-picker-dismiss into main
3 files +25 -0
resources/components/DateRangePicker.stxmodified+11-0
Changes to resources/components/DateRangePicker.stx
@@ -181,6 +181,16 @@ function pickLeftMonth(e) { pickSetYm(pickYearOf(calYm()), Number(e.target.value
181181function pickLeftYear(e) { pickSetYm(Number(e.target.value), pickMonthIdx(calYm()), false) }
182182function pickRightMonth(e) { pickSetYm(pickYearOf(pickRightYm()), Number(e.target.value), true) }
183183function pickRightYear(e) { pickSetYm(Number(e.target.value), pickMonthIdx(pickRightYm()), true) }
184// A native <details> only closes from its own summary, so an open panel would
185// otherwise sit there after the pointer moves on. The transparent .drp-backdrop
186// below covers the rest of the page while the panel is open; a click on it lands
187// here and closes the panel, the same way clicking away from a menu should.
188function pickClose(e) {
189 const d = e.currentTarget.closest('details')
190 if (d) d.removeAttribute('open')
191 selStart.set('')
192 selHover.set('')
193}
184194function pickEscape(e) {
185195 if (e.key !== 'Escape') return
186196 selStart.set('')
@@ -194,6 +204,7 @@ function pickEscape(e) {
194204 <i class="i-hugeicons-calendar-03" aria-hidden="true"></i>
195205 <span>{{ summary }}</span>
196206 </summary>
207 <div class="drp-backdrop" @click="pickClose" aria-hidden="true"></div>
197208 <div class="date-popover drp" role="dialog" aria-label="Reporting period">
198209 <div class="drp-presets" role="list">
199210 <button type="button" role="listitem" :class="pickPresetClass('today')" @click="pickApply('today')">Today</button>