Skip to content

SUrlField <s-url-field> ​

A text input for web addresses. SUrlField is the typed Vue 3 wrapper for Shopify's Polaris <s-url-field> web component.

ts
import { SUrlField } from 'polaris-vue-elements'

Best practices ​

  • Validate URLs yourself. The browser's built-in URL validation is minimal and varies between browsers, so add your own checks for structure, allowed protocols and the formats your use case accepts.
  • Show the format you expect. Tell merchants whether to include a protocol, which protocols are allowed and what kind of URL you want. A complete example URL in the placeholder makes this clear.
  • Decide how to handle a missing protocol. Merchants often leave off https://. Choose whether to add it for them, accept URLs without it, or show an error that explains what's missing.
  • Pick length limits for where the URL is used. Browsers and servers handle different maximum lengths, so set maxLength based on the URL's destination rather than an arbitrary number, and mention the limit when it matters.
  • Explain what the URL is for. Use the label and details to make the purpose clear, since a product image URL, a social profile link and an external reference each call for something different.
vue
<SUrlField label="Product image URL" placeholder="https://example.com/images/product.jpg" details="Link directly to a JPG or PNG file." />

See Shopify's best practices for <s-url-field> for the full guidance.

Example ​

Value: (empty)

vue
<script setup>
import { ref } from 'vue'
import { SUrlField } from 'polaris-vue-elements'

const value = ref('')
</script>

<template>
  <SUrlField label="Website" placeholder="https://example.com" v-model="value" />
  <p>Value: {{ value }}</p>
</template>

v-model ​

v-model on <SUrlField> binds to the value property and listens for the input DOM event.

template
<SUrlField v-model="value" />

is equivalent to:

template
<SUrlField :value="value" @input="value = $event.target.value" />

Props ​

PropTypeDescription
autocomplete"photo" | "url" | "impp" | "home impp" | "mobile impp" | "fax impp" | "pager impp" | "on" … (15 more)A hint as to the intended content of the field. When set to on (the default), this property indicates that the field should support autofill, but you do not have any more semantic information on the intended contents. When set to off, you are indicating that this field contains sensitive information, or contents that are never saved, like one-time codes. Alternatively, you can provide value which describes the specific data you would like to be entered into this field during autofill.
defaultValuestringThe default value for the field.
detailsanyAdditional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user. This will also be exposed to screen reader users.
disabledbooleanDisables the field, disallowing any interaction.
erroranyIndicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
idstringA unique identifier for the element.
labelanyContent to use as the field label.
labelAccessibilityVisibility"visible" | "exclusive"Changes the visibility of the component's label. - visible: the label is visible to all users. - exclusive: the label is visually hidden but remains in the accessibility tree.
maxLengthnumberSpecifies the maximum number of characters allowed.
minLengthnumberSpecifies the min number of characters allowed.
namestringAn identifier for the field that is unique within the nearest containing form.
placeholderstringA short hint that describes the expected value of the field.
readOnlybooleanThe field cannot be edited by the user. It is focusable will be announced by screen readers.
requiredbooleanWhether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the error property.
valuestringThe current value for the field. If omitted, the field will be empty.

Some type columns above are truncated for readability; the full union is available in the library's generated TypeScript types (src/lib/generated/types.ts).

Events ​

EventType
blurFocusEvent
changeEvent
focusFocusEvent
inputEvent

Listen for these with @blur-style listeners on <SUrlField>.

Slots ​

SlotDescription
details
error

Released under the MIT License. Vue logo by Evan You, CC BY-NC-SA 4.0.