Skip to content

Commit

Permalink
[form-builder] Fix input type in URLInput when allowing relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Feb 4, 2021
1 parent 468c40f commit 011bf9f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@sanity/form-builder/src/inputs/UrlInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {get} from 'lodash'
import React from 'react'
import {StringSchemaType} from '@sanity/types'
import {TextInput} from '@sanity/ui'
import {useId} from '@reach/auto-id'
import {FormField} from '@sanity/base/components'
import PatchEvent, {set, unset} from '../PatchEvent'
import {getValidationRule} from '../utils/getValidationRule'
import {Props} from './types'

const UrlInput = React.forwardRef(function UrlInput(
Expand All @@ -21,6 +23,8 @@ const UrlInput = React.forwardRef(function UrlInput(
},
[onChange]
)
const uriRule = getValidationRule(type, 'uri')
const inputType = uriRule && get(uriRule, 'constraint.options.allowRelative') ? 'text' : 'url'
return (
<FormField
level={level}
Expand All @@ -31,7 +35,7 @@ const UrlInput = React.forwardRef(function UrlInput(
inputId={inputId}
>
<TextInput
type="url"
type={inputType}
inputMode="url"
id={inputId}
customValidity={errors.length > 0 ? errors[0].item.message : ''}
Expand Down

0 comments on commit 011bf9f

Please sign in to comment.