Skip to content

Commit

Permalink
Fix(web-twig): Do not render input props when set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Oct 25, 2023
1 parent d8368d1 commit 30dba34
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
multiple
/>

<!-- Render with dynamic multiple attribute -->
<FileUploaderInput
accept="*.avif,*.jpg,*.png,*.webp"
id="example-input-html-attributes"
multiple={false}
/>

<!-- Render with dynamic multiple attribute -->
<FileUploaderInput
accept="*.avif,*.jpg,*.png,*.webp"
id="example-input-html-attributes"
multiple={null}
/>

<!-- Render with UNSAFE props -->
<FileUploaderInput
id="example-input-unsafe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@
</path></svg> <label for="example-input-html-attributes" class="FileUploaderInput__dropZoneLabel"><span class="FileUploaderInput__link link-primary link-underlined">Upload your file</span> <span class="FileUploaderInput__dragAndDropLabel">or drag and drop here</span></label>
</div>
</div>
<!-- Render with dynamic multiple attribute -->

<div class="FileUploaderInput" data-spirit-element="wrapper">
<input accept="*.avif,*.jpg,*.png,*.webp" type="file" id="example-input-html-attributes" class="FileUploaderInput__input" data-spirit-element="input">
<div class="FileUploaderInput__dropZone" data-spirit-element="dropZone">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12.3752 3.0625C12.2585 3.02083 12.1335 3 12.0002 3C11.8669 3 11.7419 3.02083 11.6252 3.0625C11.5085 3.10417 11.4002 3.175 11.3002 3.275L6.7002 7.875C6.51686 8.05833 6.4252 8.29167 6.4252 8.575C6.4252 8.85833 6.51686 9.09167 6.7002 9.275C6.88353 9.45833 7.12103 9.55417 7.4127 9.5625C7.70436 9.57083 7.94186 9.48333 8.1252 9.3L11.0002 6.425L11.0002 15.575C11.0002 15.8583 11.096 16.0958 11.2877 16.2875C11.4794 16.4792 11.7169 16.575 12.0002 16.575C12.2835 16.575 12.521 16.4792 12.7127 16.2875C12.9044 16.0958 13.0002 15.8583 13.0002 15.575L13.0002 6.425L15.8752 9.3C16.0585 9.48333 16.296 9.57083 16.5877 9.5625C16.8794 9.55417 17.1169 9.45833 17.3002 9.275C17.4835 9.09167 17.5752 8.85833 17.5752 8.575C17.5752 8.29167 17.4835 8.05833 17.3002 7.875L12.7002 3.275C12.6002 3.175 12.4919 3.10417 12.3752 3.0625Z" fill="currentColor">
</path>
<path d="M3.5875 20.4125C3.97917 20.8042 4.45 21 5 21H19C19.55 21 20.0208 20.8042 20.4125 20.4125C20.8042 20.0209 21 19.55 21 19V17C21 16.7167 20.9042 16.4792 20.7125 16.2875C20.5208 16.0959 20.2833 16 20 16C19.7167 16 19.4792 16.0959 19.2875 16.2875C19.0958 16.4792 19 16.7167 19 17V19H5V17C5 16.7167 4.90417 16.4792 4.7125 16.2875C4.52083 16.0959 4.28333 16 4 16C3.71667 16 3.47917 16.0959 3.2875 16.2875C3.09583 16.4792 3 16.7167 3 17V19C3 19.55 3.19583 20.0209 3.5875 20.4125Z" fill="currentColor">
</path></svg> <label for="example-input-html-attributes" class="FileUploaderInput__dropZoneLabel"><span class="FileUploaderInput__link link-primary link-underlined">Upload your file</span> <span class="FileUploaderInput__dragAndDropLabel">or drag and drop here</span></label>
</div>
</div>
<!-- Render with dynamic multiple attribute -->

<div class="FileUploaderInput" data-spirit-element="wrapper">
<input accept="*.avif,*.jpg,*.png,*.webp" type="file" id="example-input-html-attributes" class="FileUploaderInput__input" data-spirit-element="input">
<div class="FileUploaderInput__dropZone" data-spirit-element="dropZone">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12.3752 3.0625C12.2585 3.02083 12.1335 3 12.0002 3C11.8669 3 11.7419 3.02083 11.6252 3.0625C11.5085 3.10417 11.4002 3.175 11.3002 3.275L6.7002 7.875C6.51686 8.05833 6.4252 8.29167 6.4252 8.575C6.4252 8.85833 6.51686 9.09167 6.7002 9.275C6.88353 9.45833 7.12103 9.55417 7.4127 9.5625C7.70436 9.57083 7.94186 9.48333 8.1252 9.3L11.0002 6.425L11.0002 15.575C11.0002 15.8583 11.096 16.0958 11.2877 16.2875C11.4794 16.4792 11.7169 16.575 12.0002 16.575C12.2835 16.575 12.521 16.4792 12.7127 16.2875C12.9044 16.0958 13.0002 15.8583 13.0002 15.575L13.0002 6.425L15.8752 9.3C16.0585 9.48333 16.296 9.57083 16.5877 9.5625C16.8794 9.55417 17.1169 9.45833 17.3002 9.275C17.4835 9.09167 17.5752 8.85833 17.5752 8.575C17.5752 8.29167 17.4835 8.05833 17.3002 7.875L12.7002 3.275C12.6002 3.175 12.4919 3.10417 12.3752 3.0625Z" fill="currentColor">
</path>
<path d="M3.5875 20.4125C3.97917 20.8042 4.45 21 5 21H19C19.55 21 20.0208 20.8042 20.4125 20.4125C20.8042 20.0209 21 19.55 21 19V17C21 16.7167 20.9042 16.4792 20.7125 16.2875C20.5208 16.0959 20.2833 16 20 16C19.7167 16 19.4792 16.0959 19.2875 16.2875C19.0958 16.4792 19 16.7167 19 17V19H5V17C5 16.7167 4.90417 16.4792 4.7125 16.2875C4.52083 16.0959 4.28333 16 4 16C3.71667 16 3.47917 16.0959 3.2875 16.2875C3.09583 16.4792 3 16.7167 3 17V19C3 19.55 3.19583 20.0209 3.5875 20.4125Z" fill="currentColor">
</path></svg> <label for="example-input-html-attributes" class="FileUploaderInput__dropZoneLabel"><span class="FileUploaderInput__link link-primary link-underlined">Upload your file</span> <span class="FileUploaderInput__dragAndDropLabel">or drag and drop here</span></label>
</div>
</div>
<!-- Render with UNSAFE props -->

<div class="FileUploaderInput" data-spirit-element="wrapper">
Expand Down
2 changes: 1 addition & 1 deletion packages/web-twig/src/Twig/PropsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function renderInputProps(Environment $environment, array $props, $allowe
$transferringAttributes = [];
foreach ($props as $propName => $propValue) {
if (in_array($propName, self::VALIDATION_ATTRIBUTES, true) || in_array($propName, $allowedAttributes)) {
if (! is_null($propValue) && $propValue !== '') {
if (! is_null($propValue) && $propValue !== '' && $propValue !== false) {
$transferringAttributes[$propName] = $propValue;
}
}
Expand Down

0 comments on commit 30dba34

Please sign in to comment.