Skip to content

dialog.showOpenDialog with 'openDirectory' selects files instead of directories in Electron v35.x (Linux) #791

Open
@Avinash1721

Description

@Avinash1721

Describe the bug

When using dialog.showOpenDialog with the properties: ['openDirectory'] option, I'm observing incorrect behavior specifically in Electron applications built with the Electron-Vite React template when running on Linux.

This issue manifests with Electron v35.x.x (specifically tested with ^35.1.5), where the dialog incorrectly allows users to select and return file paths instead of exclusively directory paths.

Crucially, this behavior is a regression:

The exact same dialog code works as expected (only allowing directory selection) when tested in a vanilla Electron Fiddle setup using Electron v35.x.x.

The same Electron-Vite React template project functions correctly (only allowing directory selection) when downgraded to Electron v28.x.x (e.g., ^28.2.0).
This suggests a potential interaction or compatibility issue between Electron v35.x.x and how the Electron-Vite React template is bundling or configuring the application on Linux.

Expected Behavior:

When dialog.showOpenDialog is invoked with properties: ['openDirectory'] within an Electron-Vite React application, the native file dialog should:

  • Visually restrict selection to directories only (e.g., files should be greyed out or not displayed as selectable).
  • Upon selection and confirmation by the user, dialog.showOpenDialog should only return a valid path to a directory.

Actual Behavior:

In Electron v35.x.x when used with the Electron-Vite React template on Linux:

  • The native file dialog, despite having openDirectory specified, allows users to single-click and select individual files within folders.
  • The "Select Folder" (or custom buttonLabel) button remains active when a file is selected.
  • When a file is selected and the button is clicked, dialog.showOpenDialog returns the file path of the selected file in the filePaths array, instead of a directory path.

Electron Version: ^35.1.5 (Reproduces) and ^28.2.0 (Works correctly)
Operating System: Ubuntu 20.04.5 LTS (Focal Fossa), GNOME 3.36.9, x64
Gist: https://gist.github.com/Avinash1721/db028e09e13747a9bcdb2c49104ed431

Version Details (Crucial for Reproduction):

This bug reproduces with the following dependency versions in package.json:

"electron": "^35.1.5"
"electron-builder": "^25.1.8"
"electron-vite": "^3.1.0"

The functionality works correctly with the following dependency versions:

"electron": "^28.2.0"
"electron-builder": "^24.9.1"
"electron-vite": "^3.1.0"

Electron-Vite Version

3.1.0

Electron Version

35.1.5

Vite Version

6.2.6

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions