@@ -64,6 +64,39 @@ function fileInputToGooglePickerMimeTypes(accept?: string): string | null {
6464 return mimeTypes . join ( "," ) . replace ( / \s + / g, "" ) ;
6565}
6666
67+ const PICKER_ZINDEX_STYLE_ID = "google-picker-zindex" ;
68+
69+ /**
70+ * Raise the picker above the file manager modal.
71+ *
72+ * The picker renders into elements Google appends to <body>, outside the React
73+ * tree, so its stacking has to be raised from the outside. `setZIndex` is not
74+ * part of the public PickerBuilder API — it is absent from both Google's
75+ * reference and @types/google.picker — so calling it unconditionally throws
76+ * `TypeError: setZIndex is not a function` and the picker never opens.
77+ * Feature-detect it, and style the injected dialog as the fallback that
78+ * actually does the work today.
79+ */
80+ function raisePickerAboveModals ( builder : unknown ) : void {
81+ const zIndexAwareBuilder = builder as {
82+ setZIndex ?: ( zIndex : number ) => void ;
83+ } ;
84+ if ( typeof zIndexAwareBuilder . setZIndex === "function" ) {
85+ zIndexAwareBuilder . setZIndex ( Z_INDEX_OVER_FILE_MANAGER_MODAL ) ;
86+ }
87+
88+ if ( document . getElementById ( PICKER_ZINDEX_STYLE_ID ) !== null ) {
89+ return ;
90+ }
91+
92+ const style = document . createElement ( "style" ) ;
93+ style . id = PICKER_ZINDEX_STYLE_ID ;
94+ // Class names of the dialog and backdrop that the picker appends to <body>.
95+ // The backdrop is appended first, so an equal z-index keeps the dialog above it.
96+ style . textContent = `.picker-dialog, .picker-dialog-bg { z-index: ${ Z_INDEX_OVER_FILE_MANAGER_MODAL } !important; }` ;
97+ document . head . appendChild ( style ) ;
98+ }
99+
67100class GoogleDrivePickerService {
68101 private config : GoogleDriveConfig | null = null ;
69102 private tokenClient : TokenClientWithCallback | null = null ;
@@ -214,9 +247,7 @@ class GoogleDrivePickerService {
214247 this . pickerCallback ( data , resolve , reject ) ,
215248 ) ;
216249
217- ( builder as unknown as { setZIndex ( z : number ) : void } ) . setZIndex (
218- Z_INDEX_OVER_FILE_MANAGER_MODAL ,
219- ) ;
250+ raisePickerAboveModals ( builder ) ;
220251
221252 if ( options . multiple ) {
222253 builder . enableFeature ( window . google . picker . Feature . MULTISELECT_ENABLED ) ;
0 commit comments