File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
libs/web-components/src/components Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 1- <svelte:options customElement =" goa-focus-trap" />
1+ <svelte:options
2+ customElement ={{
3+ tag : " goa-focus-trap" ,
4+ props : {
5+ preventScrollIntoView : {
6+ attribute : " prevent-scroll-into-view" ,
7+ type : " Boolean" ,
8+ },
9+ },
10+ }}
11+ />
212
313<script lang =" ts" >
414 import { onMount , tick } from " svelte" ;
717 // allow for outside control of whether focus trap should re-focus the first element is open/closed (see Drawer)
818 export let open: boolean = false ;
919
20+ export let preventScrollIntoView: boolean = false ;
21+
1022 // Private
1123
1224 let rootEl: HTMLElement ;
150162 // If the focus element is at the bottom, we want to automatically scroll down to the focused element (when user uses keyboard)
151163 const focusedElement = e ?.target ;
152164
153- if (focusedElement && focusedElement instanceof HTMLElement ) {
165+ if (
166+ ! preventScrollIntoView &&
167+ focusedElement &&
168+ focusedElement instanceof HTMLElement
169+ ) {
154170 focusedElement .scrollIntoView ({ behavior: " smooth" , block: " center" });
155171 }
156172 }
Original file line number Diff line number Diff line change 131131 on: _open={open }
132132 padded =" false"
133133 tabindex =" -1"
134+ prevent-scroll-into-view ={true }
134135>
135136 <goa-button
136137 bind:this ={_targetEl }
Original file line number Diff line number Diff line change 88 type : " Boolean" ,
99 attribute : " disable-global-close-popover" ,
1010 },
11+ preventScrollIntoView : {
12+ attribute : " prevent-scroll-into-view" ,
13+ type : " Boolean" ,
14+ },
1115 },
1216 }}
1317/>
3539 export let width: string = " " ;
3640 export let height: " full" | " wrap-content" = " wrap-content" ;
3741
42+ // flag passed to the FocusTrap that will prevent unwanted scrolling
43+ export let preventScrollIntoView: boolean = false ;
44+
3845 // allows to override the default padding when content needs to be flush with boundries
3946 export let padded: string = " true" ;
4047
401408 style (" padding" , _padded ? " var(--goa-space-m)" : " 0" ),
402409 )}
403410 >
404- <goa-focus-trap open =" true" >
411+ <goa-focus-trap open ="true" prevent-scroll-into-view ={ preventScrollIntoView || undefined } >
405412 <div bind:this ={_focusTrapEl }>
406413 <slot />
407414 </div >
You can’t perform that action at this time.
0 commit comments