Skip to content

[bug] dialog.open + multiple + directory can only return one directory #4091

@martpie

Description

@martpie

Describe the bug

const selectedFolders = await dialog.open({
    directory: true,
    multiple: true,
});

only allows you to select a single directory.

Screen.Recording.2022-05-09.at.19.11.20.mov

Reproduction

  1. Create a tauri app with create react-app
  2. Enable dialog in tauri config
  3. Use the following code as component:
import React, { useCallback, useState } from 'react';
import * as dialog from '@tauri-apps/api/dialog';

const Root: React.FC = () => {
  const [folders, setFolders] = useState<string[]>([]);

  const onOpen = useCallback(async () => {
    const selectedFolders = await dialog.open({
      directory: true,
      multiple: true,
    });

    if (selectedFolders === null) {
      setFolders([]);
    } else if (typeof selectedFolders === 'string') {
      setFolders([selectedFolders]);
    } else {
      setFolders(selectedFolders);
    }
  }, []);

  return (
    <>
      <button onClick={onOpen}>Open folder</button>
      <br />
      {folders.join(',')}
    </>
  );
};

export default Root;
  1. Launch app, click on button, try to to open multiple directories

Expected behavior

It should allow the user to select multiple directories at once :]

Platform and versions

Environment
  › OS: Mac OS 12.3.1 X64
  › Node.js: 18.0.0
  › npm: 8.6.0
  › pnpm: Not installed!
  › yarn: 1.22.18
  › rustup: Not installed!
  › rustc: 1.59.0
  › cargo: 1.59.0
  › Rust toolchain:

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.10
  › @tauri-apps/api [NPM]: 1.0.0-rc.5
  › tauri [RUST]: 1.0.0-rc.9,
  › tauri-build [RUST]: 1.0.0-rc.8,
  › tao [RUST]: 0.8.4,
  › wry [RUST]: 0.16.0,

App
  › build-type: bundle
  › CSP: default-src 'none'; img-src 'self' data:; media-src 'self'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://api.github.com; font-src 'self' data:
  › distDir: ../build
  › devPath: http://localhost:3000/
  › framework: React

App directory structure
  ├─ node_modules
  ├─ public
  ├─ src-tauri
  ├─ build
  ├─ .git
  └─ src


### Stack trace

_No response_

### Additional context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions