Skip to content

SlugInput

The name something will have in an address. The fixed part of the address is shown in front, and whatever is typed turns into lowercase words joined by dashes.

import { SlugInput } from '@sypnia/ui/react'

On this page
  1. An address
  2. States
  3. When to use it
  4. For everyone
  5. Props

An address

Type «Mi Tienda Nueva!»: it is tidied as you type. Use slugify to propose one from a name.

sypnia.com/

Lowercase letters, numbers and dashes. It cannot be changed later.

Code
import { useState } from 'react';
import { Field, FormGrid, Input, SlugInput, slugify } from '@sypnia/ui/react';

export default function Basic() {
  const [name, setName] = useState('Northwind Store');
  const [slug, setSlug] = useState('northwind-store');
  const [touched, setTouched] = useState(false);
  return (
    <FormGrid>
      <Field label="Project name">
        <Input value={name} onChange={(e) => { setName(e.target.value); if (!touched) setSlug(slugify(e.target.value).replace(/-+$/, '')); }} />
      </Field>
      <Field label="Address" hint="Lowercase letters, numbers and dashes. It cannot be changed later.">
        <SlugInput prefix="sypnia.com/" value={slug} onChange={(s) => { setSlug(s); setTouched(true); }} />
      </Field>
    </FormGrid>
  );
}

States

With an error that says how to fix it, and disabled.

sypnia.com/

«orders» is taken. Try orders-eu or northwind-orders.

sypnia.com/

Set when the project was created.

Code
import { Field, FormGrid, SlugInput } from '@sypnia/ui/react';

export default function States() {
  return (
    <FormGrid>
      <Field label="Address" error="«orders» is taken. Try orders-eu or northwind-orders.">
        <SlugInput prefix="sypnia.com/" defaultValue="orders" />
      </Field>
      <Field label="Address" hint="Set when the project was created.">
        <SlugInput disabled prefix="sypnia.com/" defaultValue="northwind-store" />
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • A name ends up in an address or an identifier: a project, a workspace, a page.
  • The person should see the whole address while they type, not only their part.

Do not use it when

  • The name is only shown to people and can have spaces and capitals: Input.
  • It is a whole address typed by the person: UrlInput.

For everyone

  • It is a plain text box; the fixed part in front is not editable and is not part of the value.
  • Capitals become lowercase, accents are dropped, and spaces and signs become one dash, as the person types. Nothing is refused: it is tidied.
  • Say in the hint what the address is for and whether it can be changed later.
  • Inside a Field it takes the label, the hint and the error by itself; alone, give it an aria-label.

Props

SlugInputTypeDefault
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
defaultValue string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
maxLength number
name

Sends the slug with the form, under this name.

string
onChange ((slug: string) => void)
placeholder string
prefix

The fixed part of the address shown before the value: `sypnia.com/`.

string
value string
  1. An address
  2. States
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms