Treat defaultValue from Blockly prompts properly
That is, as the default value for the input, not the placeholder.
This commit is contained in:
1 parent
adf7270b08
commit
236948a2d2
3 files changed
+11
-5
No files matched your search
@@ -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>
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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}
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user