Skip to content

feat(VFileUpload, VFileInput): strict-accept prop #21576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

J-Sek
Copy link
Contributor

@J-Sek J-Sek commented Jun 14, 2025

Description

Usually, accept is considered a "mild suggestion" by the browser, and is misunderstood by developers as a way to reliably filter files on the frontend

  • it actually only affects opening native file picker and can be easily dismissed
  • drag & drop ignores accept and it is a default behavior (not the fault of our implementation)
  • when used with webkitdirectory, it makes the native file picker unusable

This PR changes default behavior to make accept strict. While doing so, it may introduce UX degradation - user might be think the page is broken, because accept rules are not obvious or he does not know whether valid files are contained within a folder he drops. New rejected event lets developer handle it by flashing warning with Snackbar or showing small dismissable alert next to the field.

Outlined changes:

  • applies strict-accept for drag&drop and regular selection
  • avoids passing accept to the underlying input when webkitdirectory is present

TBD: it is quite easy to make a typo in accept value and I am considering prop validation. Dropped it last minute, because it would be relatively larger in comparison to existing prop validators. There are however only 11 groups, so maybe we can revisit this enhancement (source » [...document.querySelectorAll('h2')].map(x => x.innerText)).

resolves #21150

Markup:

<template>
  <v-app>
    <v-container>
      <v-combobox v-model="accept" :items="suggestions" label="accept" clearable />
      <v-alert type="info">
        Verification:
        <ul>
          <li>check selecting with click</li>
          <li>set `webkitdirectory` to directory selection</li>
          <li>drag&drop files or forders with different "accept" value (with and without `webkitdirectory`)</li>
        </ul>
      </v-alert>
      <v-divider class="mb-6" />
      <v-sheet class="pa-2 mb-6" elevation="4">
        Native input for reference: <input :accept="accept" type="file" multiple>
      </v-sheet>
      <!-- <v-file-input v-model="files" :accept="accept" clearable multiple webkitdirectory /> -->
      <v-file-input v-model="files" :strict-accept="accept" clearable multiple />
      <pre>files: {{ files }}</pre>
      <!-- <v-file-upload :accept="accept" multiple webkitdirectory /> -->
      <v-file-upload :strict-accept="accept" multiple />
    </v-container>
  </v-app>
</template>

<script setup>
  import { ref } from 'vue'

  const files = ref([])

  const accept = ref(null)
  const suggestions = [
    '.pdf',
    'image/jpeg',
    'image/*',
    'image/png, image/jpeg',
    '.png, .jpg, .jpeg',
    'image/*,video/*',
    'image/*,plain/text',
    'plain/text',
    '.doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  ]
</script>

@J-Sek J-Sek self-assigned this Jun 14, 2025
@J-Sek J-Sek requested review from jcjp and johnleider June 14, 2025 23:48
@J-Sek J-Sek changed the title feat(VFileUpload, VFileInput): filter files on drop and folder selection feat(VFileUpload, VFileInput): strict accept Jun 14, 2025
@J-Sek
Copy link
Contributor Author

J-Sek commented Jun 17, 2025

I am 50/50 on renaming the prop to something like strict-accept or filter-by-type. And it probably should target dev.

@johnleider
Copy link
Member

I am 50/50 on renaming the prop to something like strict-accept or filter-by-type. And it probably should target dev.

I like this idea.

@J-Sek J-Sek changed the base branch from master to dev June 18, 2025 07:04
@J-Sek J-Sek changed the title feat(VFileUpload, VFileInput): strict accept feat(VFileUpload, VFileInput): strict-accept prop Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][3.7.18] VFileUpload drag-and-drop doesn't use "accept" prop for allowed file types
5 participants