/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import React from "react"; export class TopSiteFormInput extends React.PureComponent { constructor(props) { super(props); this.state = { validationError: this.props.validationError }; this.onChange = this.onChange.bind(this); this.onMount = this.onMount.bind(this); this.onClearIconPress = this.onClearIconPress.bind(this); } componentWillReceiveProps(nextProps) { if (nextProps.shouldFocus && !this.props.shouldFocus) { this.input.focus(); } if (nextProps.validationError && !this.props.validationError) { this.setState({ validationError: true }); } // If the component is in an error state but the value was cleared by the parent if (this.state.validationError && !nextProps.value) { this.setState({ validationError: false }); } } onClearIconPress(event) { // If there is input in the URL or custom image URL fields, // and we hit 'enter' while tabbed over the clear icon, // we should execute the function to clear the field. if (event.key === "Enter") { this.props.onClear(); } } onChange(ev) { if (this.state.validationError) { this.setState({ validationError: false }); } this.props.onChange(ev); } onMount(input) { this.input = input; } renderLoadingOrCloseButton() { const showClearButton = this.props.value && this.props.onClear; if (this.props.loading) { return (
); } else if (showClearButton) { return (