Stop file upload component 'jumping' on focus #2205
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Stop file upload component 'jumping' on focus.
Why
While working on #2194 , we noticed that the file upload component 'jumps' slightly to the left on focus. Example (in Safari, but this affects other browsers too):
Screen.Recording.2021-04-26.at.16.01.58.BEFORE.mov
This is related to some CSS and a comment in the code, which is applied on focus:
We can understand why this code was added by observing the effect of removing it:
Screen.Recording.2021-04-26.at.16.06.15.mov
When this CSS is removed, the focus state and the file upload button overlap on the left-hand side.
So... we need to add some padding-left?
The component has bottom and top padding applied by default, but left and right padding is only added on focus (see the code above). What happens if we add padding by default instead of waiting for focus, to prevent anything moving around on focus?
This initially looks good on focus, but we can see that when the focus state is removed the file upload button is out of line with the text above it. This explains why we were initially adding a negative margin.
Setting padding and negative margin by default
Instead of waiting until focus, we can add padding and a negative left margin by default:
Screen.Recording.2021-04-26.at.16.21.11.mov
Cross Browser testing