Skip to content

Commit

Permalink
- Renaming content prop to initialContent and prefilling the state in…
Browse files Browse the repository at this point in the history
… the constructor

- Adding type="button" to buttons
  • Loading branch information
youknowriad committed Mar 28, 2017
1 parent b4ca382 commit c820350
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion editor/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Editor {

render() {
wp.element.render(
<EditorLayout content={ this.settings.content } />,
<EditorLayout initialContent={ this.settings.content } />,
document.getElementById( this.id )
);
}
Expand Down
13 changes: 3 additions & 10 deletions editor/editor/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ import EditorText from './mode/text';
import EditorVisual from './mode/visual';

class Layout extends wp.element.Component {
constructor() {
constructor( props ) {
super( ...arguments );
this.switchMode = this.switchMode.bind( this );
this.changeHtml = this.changeHtml.bind( this );
this.changeBlocks = this.changeBlocks.bind( this );
this.state = {
mode: 'visual',
html: '',
blocks: []
html: props.initialContent,
blocks: wp.blocks.parse( this.props.initialContent )
};
}

componentDidMount() {
this.setState( {
html: this.props.content,
blocks: wp.blocks.parse( this.props.content )
} );
}

switchMode( newMode ) {
// TODO: we need a serializer from blocks here
const html = this.state.html;
Expand Down
5 changes: 2 additions & 3 deletions editor/editor/mode-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class ModeSwitcher extends wp.element.Component {
};
}

toggle( event ) {
event.preventDefault();
toggle() {
this.setState( {
opened: ! this.state.opened
} );
Expand Down Expand Up @@ -40,7 +39,7 @@ class ModeSwitcher extends wp.element.Component {
<div className="editor-mode-switcher__content">
<div className="editor-mode-switcher__arrow" />
{ modes.map( ( mode ) =>
<button key={ mode.value } onClick={ switchMode( mode.value ) }>
<button key={ mode.value } type="button" onClick={ switchMode( mode.value ) }>
{ mode.label }
</button>
) }
Expand Down
4 changes: 2 additions & 2 deletions editor/inserter/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class InserterButton extends wp.element.Component {
};
}

toggle( event ) {
event.preventDefault();
toggle() {
this.setState( {
opened: ! this.state.opened
} );
Expand All @@ -27,6 +26,7 @@ class InserterButton extends wp.element.Component {
<button
className="inserter__button-toggle"
onClick={ this.toggle }
type="button"
aria-label="Add a block"
>
<span className="dashicons dashicons-plus" />
Expand Down

0 comments on commit c820350

Please sign in to comment.