Skip to content

Commit

Permalink
Treat defaultValue from Blockly prompts properly
Browse files Browse the repository at this point in the history
That is, as the default value for the input, not the placeholder.
  • Loading branch information
towerofnix committed Dec 7, 2018
1 parent adf7270 commit 236948a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/prompt/prompt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ const PromptComponent = props => (
<input
autoFocus
className={styles.variableNameTextInput}
defaultValue={props.defaultValue}
name={props.label}
placeholder={props.placeholder}
onChange={props.onChange}
onFocus={props.onFocus}
onKeyPress={props.onKeyPress}
/>
</Box>
Expand Down Expand Up @@ -133,14 +134,15 @@ const PromptComponent = props => (
);

PromptComponent.propTypes = {
defaultValue: PropTypes.string,
isStage: PropTypes.bool.isRequired,
label: PropTypes.string.isRequired,
onCancel: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onFocus: PropTypes.func.isRequired,
onKeyPress: PropTypes.func.isRequired,
onOk: PropTypes.func.isRequired,
onOptionSelection: PropTypes.func.isRequired,
placeholder: PropTypes.string,
showMoreOptions: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired
};
Expand Down
2 changes: 1 addition & 1 deletion src/containers/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ class Blocks extends React.Component {
/>
{this.state.prompt ? (
<Prompt
defaultValue={this.state.prompt.defaultValue}
isStage={vm.runtime.getEditingTarget().isStage}
label={this.state.prompt.message}
placeholder={this.state.prompt.defaultValue}
showMoreOptions={this.state.prompt.showMoreOptions}
title={this.state.prompt.title}
onCancel={this.handlePromptClose}
Expand Down
8 changes: 6 additions & 2 deletions src/containers/prompt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Prompt extends React.Component {
handleKeyPress (event) {
if (event.key === 'Enter') this.handleOk();
}
handleFocus (event) {
event.target.select();
}
handleOk () {
this.props.onOk(this.state.inputValue, this.state.optionSelection);
}
Expand All @@ -36,13 +39,14 @@ class Prompt extends React.Component {
render () {
return (
<PromptComponent
defaultValue={this.props.defaultValue}
isStage={this.props.isStage}
label={this.props.label}
placeholder={this.props.placeholder}
showMoreOptions={this.props.showMoreOptions}
title={this.props.title}
onCancel={this.handleCancel}
onChange={this.handleChange}
onFocus={this.handleFocus}
onKeyPress={this.handleKeyPress}
onOk={this.handleOk}
onOptionSelection={this.handleOptionSelection}
Expand All @@ -52,11 +56,11 @@ class Prompt extends React.Component {
}

Prompt.propTypes = {
defaultValue: PropTypes.string,
isStage: PropTypes.bool.isRequired,
label: PropTypes.string.isRequired,
onCancel: PropTypes.func.isRequired,
onOk: PropTypes.func.isRequired,
placeholder: PropTypes.string,
showMoreOptions: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired
};
Expand Down

0 comments on commit 236948a

Please sign in to comment.