-
Notifications
You must be signed in to change notification settings - Fork 765
Description
Problem:
JavaScript is required to change the style of a file input if you want to show feedback that the input is a valid drop target. Currently, authors must add multiple JS listeners to file type inputs to "do their best" to show the user the UI is expecting the file drop / is a valid drop location. Without this JS, users have to guess / assume / or notice that tiny subtle hover effect (which I never noticed until I watched the below demom video demo which is quite zoomed).
<input
type="file"
ondragenter="this.classList.add('dropping')"
ondragleave="this.classList.remove('dropping')"
ondrop="this.classList.remove('dropping')"
>
<style>
input[type=file].dropping {
/* … */
}
</style>would become ✨
<input type="file">
<style>
input[type=file]:drop-target {
/* … */
}
</style>drop-target.mp4
Proposal: :drop-target
Remove the JS requirement and expose the state the browser is keeping private.
input[type="file"] {
/* … */
&:drop-target {
outline: 2px dashed Highlight;
@media (prefers-reduced-motion: no-preference) {
animation: drop-zone 1.5s ease-out infinite;
}
}
}This selector would activate when the user's drag coordinates are intersecting with the elements bounds, and would deactivate when the user moves the file off of the element. This selector is up for discussion about whether it should work for all inputs/elements, or just the file input.
This could also be combined with :has() so forms and UIs can know if there is a drag event happening on a child element, and it can compliment the state by reducing noise (for example):
fieldset:has(:drop-target) :not(:drop-target) {
opacity: .5;
}Resources:
https://www.w3.org/TR/selectors-4/