Skip to content

Commit

Permalink
make hardEscape true by default
Browse files Browse the repository at this point in the history
  • Loading branch information
joduplessis committed Jun 15, 2024
1 parent 55c9a9d commit 7aaf970
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/popover/popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ export const OffscreenDetection = () => {
<View>
<View row>
<Popover
__globalEscape
arrow
width="fit-content"
isVisible={visible}
Expand All @@ -385,7 +384,6 @@ export const OffscreenDetection = () => {
</Popover>
<Flexer />
<Popover
__globalEscape
arrow
width="fit-content"
isVisible={visible}
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/popover/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React, { cloneElement, forwardRef, ReactElement, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useFocus, useId, View } from '..'
import {
Expand Down Expand Up @@ -26,7 +27,7 @@ export const PopoverContent = forwardRef((props: CoreViewProps, ref) => (
export type PopoverAnchor = PopoutPosition

export type PopoverProps = {
__globalEscape?: boolean
hardEscape?: boolean
__focusTrapTimeoutDelay?: number
focusTrap?: boolean
targetId?: string
Expand All @@ -41,7 +42,7 @@ export type PopoverProps = {

export const Popover = forwardRef((props: PopoverProps, ref) => {
const {
__globalEscape,
hardEscape = true,
__focusTrapTimeoutDelay = 100,
focusTrap,
targetId,
Expand Down Expand Up @@ -81,8 +82,8 @@ export const Popover = forwardRef((props: PopoverProps, ref) => {
childRef.current?.focus()
}

const handleKeyDownGlobal = (e) => {
if (__globalEscape) {
const handleKeyDownDocument = (e) => {
if (hardEscape) {
const { isEscape } = getKey(e)
if (isEscape && onDismiss) dismissPopover(e)
}
Expand All @@ -94,6 +95,7 @@ export const Popover = forwardRef((props: PopoverProps, ref) => {
if (isEscape && onDismiss) dismissPopover(e)
}


const handleClick = (e) => {
if (containerRef.current) {
if (!containerRef.current?.contains(e.target)) {
Expand All @@ -103,7 +105,7 @@ export const Popover = forwardRef((props: PopoverProps, ref) => {
}

useEvent('click', handleClick, true)
useEvent('keydown', handleKeyDownGlobal, true)
useEvent('keydown', handleKeyDownDocument, true)

useLayoutEffect(() => {
if (!id) return
Expand Down Expand Up @@ -191,3 +193,5 @@ export const Popover = forwardRef((props: PopoverProps, ref) => {
</>
)
})


0 comments on commit 7aaf970

Please sign in to comment.