Merge pull request #682 from orangemug/fix/issue-681

Fix open modal URL entry to use form submission
This commit is contained in:
Orange Mug 2020-05-14 15:32:09 +01:00 committed by GitHub
commit e3e6647e03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 19 deletions

View file

@ -11,10 +11,12 @@ class Button extends React.Component {
className: PropTypes.string,
children: PropTypes.node,
disabled: PropTypes.bool,
type: PropTypes.string,
}
render() {
return <button
type={this.props.type}
onClick={this.props.onClick}
disabled={this.props.disabled}
aria-label={this.props["aria-label"]}

View file

@ -1,10 +1,14 @@
import React from 'react'
import React, {Fragment} from 'react'
import PropTypes from 'prop-types'
import StringInput from './StringInput'
import SmallError from '../util/SmallError'
function validate (url) {
if (url === "") {
return;
}
let error;
const getProtocol = (url) => {
try {
@ -16,7 +20,20 @@ function validate (url) {
}
};
const protocol = getProtocol(url);
if (
const isSsl = window.location.protocol === "https:";
if (!protocol) {
error = (
<SmallError>
Must provide protocol {
isSsl
? <code>https://</code>
: <><code>http://</code> or <code>https://</code></>
}
</SmallError>
);
}
else if (
protocol &&
protocol === "http:" &&
window.location.protocol === "https:"
@ -61,12 +78,20 @@ class UrlInput extends React.Component {
this.props.onInput(url);
}
onChange = (url) => {
this.setState({
error: validate(url)
});
this.props.onChange(url);
}
render () {
return (
<div>
<StringInput
{...this.props}
onInput={this.onInput}
onChange={this.onChange}
/>
{this.state.error}
</div>

View file

@ -123,7 +123,8 @@ class OpenModal extends React.Component {
})
}
onOpenUrl = (url) => {
onSubmitUrl = (e) => {
e.preventDefault();
this.onStyleSelect(this.state.styleUrl);
}
@ -209,6 +210,7 @@ class OpenModal extends React.Component {
<p>
Load from a URL. Note that the URL must have <a href="https://enable-cors.org" target="_blank" rel="noopener noreferrer">CORS enabled</a>.
</p>
<form onSubmit={this.onSubmitUrl}>
<UrlInput
data-wd-key="open-modal.url.input"
type="text"
@ -216,15 +218,17 @@ class OpenModal extends React.Component {
default="Enter URL..."
value={this.state.styleUrl}
onInput={this.onChangeUrl}
onChange={this.onChangeUrl}
/>
<div>
<Button
data-wd-key="open-modal.url.button"
type="submit"
className="maputnik-big-button"
onClick={this.onOpenUrl}
disabled={this.state.styleUrl.length < 1}
>Open URL</Button>
</div>
</form>
</section>
<section className="maputnik-modal-section maputnik-modal-section--shrink">