Skip to content

Commit

Permalink
Refactor edit to set the default value for download button label
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 23, 2019
1 parent 61eebc9 commit 80e6f41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/block-library/src/file/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"downloadButtonText": {
"type": "string",
"source": "html",
"selector": "a[download]",
"default": "Download"
"selector": "a[download]"
}
}
}
12 changes: 9 additions & 3 deletions packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '@wordpress/block-editor';
import { mediaUpload } from '@wordpress/editor';
import { Component, Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __, _x } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -55,8 +55,8 @@ class FileEdit extends Component {
}

componentDidMount() {
const { attributes, noticeOperations } = this.props;
const { href } = attributes;
const { attributes, noticeOperations, setAttributes } = this.props;
const { downloadButtonText, href } = attributes;

// Upload a file drag-and-dropped into the editor
if ( isBlobURL( href ) ) {
Expand All @@ -73,6 +73,12 @@ class FileEdit extends Component {

revokeBlobURL( href );
}

if ( downloadButtonText === undefined ) {
setAttributes( {
downloadButtonText: _x( 'Download', 'button label' ),
} );
}
}

componentDidUpdate( prevProps ) {
Expand Down

0 comments on commit 80e6f41

Please sign in to comment.