Skip to content
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

Custom Forms: Allow Chrome/Firefox feature that lets the user drag and drop into file inputs #20033

Merged
merged 2 commits into from
Jan 4, 2017

Conversation

wizpig64
Copy link
Contributor

@wizpig64 wizpig64 commented Jun 3, 2016

Chrome (among other browsers) allows you to drag and drop files from the desktop into <input type="file"> form elements. Bootstrap 4's custom file input covers up the base input, so drag and drop doesn't work.

This patch disables pointer-events on the custom element so dropped files pass through to the invisible, full-height input behind it. Normal clicks work just as they did.

@cvrebert
Copy link
Collaborator

cvrebert commented Jun 3, 2016

pointer-events isn't supported in IE9-10 though, which are still supported browsers in v4.

@wizpig64
Copy link
Contributor Author

wizpig64 commented Jun 3, 2016

True, but in that case wouldn't this effectively do nothing for IE users? This is, after all, not a standard feature of <input type="file"> but a Chrome feature that I wanted bootstrap to not get in the way of.

I just tested drag and drop on jsfiddle for both IE11 and Edge, and neither of them support the functionality that Chrome does, so I doubt IE 9 or 10 have it.

Just tried it on Firefox 46 with success, for what it's worth. The changed .custom-file does look strange on Firefox: Unlike chrome, it horizontally expands the input to accommodate added files, while the text box still shows an unchanged "Choose file...". Of course it behaved like that before the patch too, but the explorer dialogue hid the sudden resizing.

@wizpig64 wizpig64 changed the title Restored functionality of dragging files into .custom-file inputs. Custom Forms: Allow Chrome/Firefox feature that lets the user drag and drop into file inputs Jun 3, 2016
@cvrebert
Copy link
Collaborator

cvrebert commented Jun 4, 2016

Huh, I wasn't aware that drag-file-into-file-input wasn't supported in IE/Edge, but you're right.
I withdraw my concern then.

@@ -210,6 +210,8 @@
.custom-file-input {
min-width: $custom-file-width;
max-width: 100%;
padding-top: $custom-file-padding-y;
padding-bottom: $custom-file-padding-y;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shorthand is still used below, so why add these?

Copy link
Contributor Author

@wizpig64 wizpig64 Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This padding is to make the hidden element match the height of the custom control. Without this extra height, files can only be dragged onto the top half of the control.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't height make more sense to set?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@wizpig64 wizpig64 Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said before, it's to make the invisible input the same height as the visible .custom-file-control. Without it, dragging something onto the lower third of the button doesn't work. changing height does the same thing while looking cleaner though, so that's how it works now.

@mdo mdo added this to the v4.1 ideas milestone Oct 10, 2016
@mdo mdo modified the milestones: v4.0.0-alpha.6, v4.1 ideas Oct 29, 2016
@mdo mdo removed the feature label Oct 29, 2016
@mdo
Copy link
Member

mdo commented Oct 29, 2016

This is less a feature and more of a slight improvement and maybe a bug fix (since this is browser behavior for many folks). Should be able to merge, but I did have a question on the use of padding vs height on the hidden input.

@wizpig64
Copy link
Contributor Author

wizpig64 commented Dec 9, 2016

Good call on height, I admit my css experience is limited.

One thing I noticed is that this change breaks cursor: pointer; as it seems to require pointer-events to work right. I tried moving that rule to the input element but (at least in chrome) the cursor still acts inconsistently: The cursor shows as a pointer everywhere except where the input's button should be. I'm not sure how to get around this, feedback welcome.

edit: Here's what I mean: https://gfycat.com/ShoddySleepyFlea - Note this shows what it would look like if the cursor style was applied to the input. As of the current commit the cursor is never a pointer.

@mdo mdo merged commit 1b194c0 into twbs:v4-dev Jan 4, 2017
@mdo mdo mentioned this pull request Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants