@seamly/web-ui 25.2.0-beta.1 → 25.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamly/web-ui",
3
- "version": "25.2.0-beta.1",
3
+ "version": "25.2.0-beta.2",
4
4
  "main": "build/dist/lib/index.js",
5
5
  "types": "build/src/javascripts/index.d.ts",
6
6
  "exports": {
@@ -2,9 +2,10 @@ import { useUserHasResponded } from 'domains/app/hooks'
2
2
  import { useConfig } from 'domains/config/hooks'
3
3
  import { useI18n } from 'domains/i18n/hooks'
4
4
  import { useVisibility } from 'domains/visibility/hooks'
5
+ import { createFocusTrap, FocusTrap } from 'focus-trap'
5
6
  import { className } from 'lib/css'
6
7
  import { ComponentChildren } from 'preact'
7
- import { forwardRef } from 'preact/compat'
8
+ import { forwardRef, useEffect, useRef } from 'preact/compat'
8
9
  import Suggestions from 'ui/components/suggestions'
9
10
  import { useSeamlyAppContainerClassNames } from 'ui/hooks/component-helper-hooks'
10
11
  import { useWindowOpenButtonFocusing } from 'ui/hooks/focus-helper-hooks'
@@ -15,11 +16,13 @@ const Chat = forwardRef<
15
16
  HTMLElement,
16
17
  { children: ComponentChildren; className?: string }
17
18
  >(({ children, className: givenClassName = '' }, forwardedRef) => {
19
+ const focusTrap = useRef<FocusTrap>(null)
18
20
  const { closeChat, isOpen, isVisible } = useVisibility()
19
21
  const focusWindowOpenButton = useWindowOpenButtonFocusing()
20
22
  const { namespace, layoutMode } = useConfig()
21
23
  const { isInline } = useSeamlyLayoutMode()
22
24
  const appContainerClassNames = useSeamlyAppContainerClassNames()
25
+ const chatSectionId = useGeneratedId()
23
26
  const headingId = useGeneratedId()
24
27
  const userHasResponded = useUserHasResponded()
25
28
  const { t } = useI18n()
@@ -52,9 +55,26 @@ const Chat = forwardRef<
52
55
  }
53
56
  }
54
57
 
58
+ useEffect(() => {
59
+ if (isVisible && layoutMode === 'window') {
60
+ focusTrap.current = createFocusTrap(`#${chatSectionId}`, {
61
+ // We set the initialFocus to false, as the `WindowOpenButton` takes care of that
62
+ initialFocus: false,
63
+ })
64
+ focusTrap.current.activate()
65
+ }
66
+
67
+ return () => {
68
+ if (focusTrap.current) {
69
+ focusTrap.current.deactivate()
70
+ }
71
+ }
72
+ }, [chatSectionId, isVisible, layoutMode])
73
+
55
74
  return (
56
75
  isVisible && (
57
76
  <section
77
+ id={chatSectionId}
58
78
  className={className(classNames)}
59
79
  onKeyDown={onKeyDownHandler}
60
80
  tabIndex={-1}