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

Remove margin between file input field and link #33

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

dontub
Copy link
Contributor

@dontub dontub commented Sep 6, 2024

The file input field is wrapped by a div with class .form-item and thus gets a bottom margin. The p element containing the link to the current file has a top margin. So there is a lot of space between input field and link. This change sets these margins to 0.

systopia-reference: 25904

@jensschuppe
Copy link
Collaborator

@dontub can you show the relevant part of the DOM (e.g. screenshot)? Maybe using #field_prefix instead of #prefix might be an option for not requiring additional CSS …

@dontub
Copy link
Contributor Author

dontub commented Sep 10, 2024

The resulting HTML is like this:

<div class="js-form-item form-item custom-control custom-file js-form-type-file form-type-file js-form-item-files-foo form-item-files-foo">
	<label for="edit-foo" class="custom-control-label">Foo</label>
	<div class="wrapper-input-file">
		<input data-drupal-selector="edit-foo" type="file" id="edit-foo" name="files[foo]" size="60" class="js-form-file form-file">
		<label for="file">Choose a file</label>
	</div>
</div>
<p class="civiremote-form-file-link">
  <a href="url/to/foo.txt" target="_blank" data-drupal-selector="edit-link" id="edit-link">foo.txt</a>
</p>

The element of type link is a RenderElement not a FormElement so there's no #field_prefix. Maybe I don't understand your idea...

@jensschuppe
Copy link
Collaborator

I thought of placing the link as #field_prefix (or rather #field_suffix) of the file form element. But I think tose only support plain text. Maybe the link can be placed in the file element's #suffix? The point is that the link would be inside the form element wrapper and thus not subject to its margins.

The file input field is wrapped by a `div` with class `.form-item` and
thus gets a bottom margin. The `p` element containing the link to the
current file has a top margin. So there is a lot of space between input
field and link. This change sets these margins to `0`.
@dontub dontub force-pushed the no-margin-between-file-form-item-and-link branch from e56341a to 3a40208 Compare October 4, 2024 14:08
@dontub
Copy link
Contributor Author

dontub commented Oct 4, 2024

#suffix has to be a string, too. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21RenderElementBase.php/class/RenderElementBase/11.x

Yet, it would be preferable if the link would be inside the form element wrapper.

@jensschuppe
Copy link
Collaborator

I think the "proper" thing to do would be creating a new render element, containing and processing both elements (the file upload field and a link element for the current file). Not sure however whether it's worth the effort only for a margin …

@dontub
Copy link
Contributor Author

dontub commented Oct 10, 2024

I've created an issue for this #40 and I'll merge this now.

@dontub dontub merged commit 47b0c85 into 1.1.x Oct 10, 2024
17 checks passed
@dontub dontub deleted the no-margin-between-file-form-item-and-link branch October 10, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants