Skip to content

Commit

Permalink
File Block: Makes the button an element button (#41239)
Browse files Browse the repository at this point in the history
* Form Block: Makese the button an element button

* update fixtures
  • Loading branch information
scruffian authored May 24, 2022
1 parent 23e3018 commit 373d545
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 18 deletions.
6 changes: 5 additions & 1 deletion packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
RichText,
useBlockProps,
store as blockEditorStore,
__experimentalElementButtonClassName,
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { useCopyToClipboard } from '@wordpress/compose';
Expand Down Expand Up @@ -301,7 +302,10 @@ function FileEdit( {
<RichText
tagName="div" // Must be block-level or else cursor disappears.
aria-label={ __( 'Download button text' ) }
className={ 'wp-block-file__button' }
className={ classnames(
'wp-block-file__button',
__experimentalElementButtonClassName
) }
value={ downloadButtonText }
withoutInteractiveFormatting
placeholder={ __( 'Add text…' ) }
Expand Down
16 changes: 14 additions & 2 deletions packages/block-library/src/file/save.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalElementButtonClassName,
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';

export default function save( { attributes } ) {
Expand Down Expand Up @@ -63,7 +72,10 @@ export default function save( { attributes } ) {
{ showDownloadButton && (
<a
href={ href }
className="wp-block-file__button"
className={ classnames(
'wp-block-file__button',
__experimentalElementButtonClassName
) }
download={ true }
aria-describedby={ describedById }
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js","showDownloadButton":true} -->
<div class="wp-block-file"><a id="wp-block-file--media-_clientId_0" href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<div class="wp-block-file"><a id="wp-block-file--media-_clientId_0" href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"showDownloadButton": true
},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n",
"innerHTML": "\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n",
"innerContent": [
"\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n"
"\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js"} -->
<div class="wp-block-file"><a id="wp-block-file--media-_clientId_0" href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<div class="wp-block-file"><a id="wp-block-file--media-_clientId_0" href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js"} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js","showDownloadButton":true} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"showDownloadButton": true
},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n",
"innerHTML": "\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button wp-element-button\" download>Download</a></div>\n",
"innerContent": [
"\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n"
"\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button wp-element-button\" download>Download</a></div>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js"} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js"} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button wp-element-button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf","displayPreview":true,"previewHeight":370} -->
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a id="wp-block-file--media-_clientId_0" href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a id="wp-block-file--media-_clientId_0" href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"previewHeight": 370
},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-file\"><object class=\"wp-block-file__embed\" data=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" type=\"application/pdf\" style=\"width:100%;height:370px\" aria-label=\"Embed of yolo.\"></object><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\">yolo</a><a href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n",
"innerHTML": "\n<div class=\"wp-block-file\"><object class=\"wp-block-file__embed\" data=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" type=\"application/pdf\" style=\"width:100%;height:370px\" aria-label=\"Embed of yolo.\"></object><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\">yolo</a><a href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n",
"innerContent": [
"\n<div class=\"wp-block-file\"><object class=\"wp-block-file__embed\" data=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" type=\"application/pdf\" style=\"width:100%;height:370px\" aria-label=\"Embed of yolo.\"></object><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\">yolo</a><a href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n"
"\n<div class=\"wp-block-file\"><object class=\"wp-block-file__embed\" data=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" type=\"application/pdf\" style=\"width:100%;height:370px\" aria-label=\"Embed of yolo.\"></object><a id=\"wp-block-file--media-_clientId_0\" href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\">yolo</a><a href=\"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-_clientId_0\">Download</a></div>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf","displayPreview":true,"previewHeight":370} -->
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a id="wp-block-file--media-_clientId_0" href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a id="wp-block-file--media-_clientId_0" href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-_clientId_0">Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf","displayPreview":true,"previewHeight":370} -->
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" type="application/pdf" style="width:100%;height:370px" aria-label="Embed of yolo."></object><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf">yolo</a><a href="http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf" class="wp-block-file__button wp-element-button" download>Download</a></div>
<!-- /wp:file -->

0 comments on commit 373d545

Please sign in to comment.