diff --git a/client/modules/IDE/components/SidebarItem.js b/client/modules/IDE/components/SidebarItem.js index 4a00c8dd..efec5e0a 100644 --- a/client/modules/IDE/components/SidebarItem.js +++ b/client/modules/IDE/components/SidebarItem.js @@ -8,6 +8,7 @@ class SidebarItem extends React.Component { super(props); this.handleKeyPress = this.handleKeyPress.bind(this); this.handleFileNameChange = this.handleFileNameChange.bind(this); + this.validateFileName = this.validateFileName.bind(this); } handleFileNameChange(event) { @@ -21,6 +22,12 @@ class SidebarItem extends React.Component { } } + validateFileName() { + if (!this.props.file.name.match(/.*\.(js|css|html|json)$/)) { + this.props.updateFileName(this.props.file.id, this.originalFileName); + } + } + render() { let itemClass = classNames({ 'sidebar__file-item': true, @@ -45,7 +52,10 @@ class SidebarItem extends React.Component { value={this.props.file.name} onChange={this.handleFileNameChange} ref="fileNameInput" - onBlur={() => this.props.hideEditFileName(this.props.file.id)} + onBlur={() => { + this.validateFileName(); + this.props.hideEditFileName(this.props.file.id); + }} onKeyPress={this.handleKeyPress} /> { + this.originalFileName = this.props.file.name; this.props.showEditFileName(this.props.file.id); setTimeout(() => this.refs.fileNameInput.focus(), 0); }}