Component API
Chipster
disabled

disabled

The disabled prop allows you to disable all interactions with the Chipster component, including adding, removing items, and input functionality.

Type Definition

type Disabled = boolean;

Basic Usage

BasicExample.tsx
import { Chipster } from '@micoblanc/chipster'
 
export default function BasicExample() {
  return (
    <Chipster disabled>
      <Chipster.ItemList />
      <Chipster.Input placeholder="Type and press Enter" />
    </Chipster>
  )
}

Advanced Usage with Dynamic State

DynamicDisableExample.tsx
export default function DynamicDisableExample() {
  const [isDisabled, setIsDisabled] = useState(false)
  const [isLoading, setIsLoading] = useState(false)
  
  const handleSubmit = async () => {
    setIsDisabled(true)
    setIsLoading(true)
    try {
      await saveData()
    } finally {
      setIsDisabled(false)
      setIsLoading(false)
    }
  }
 
  return (
    <div>
      <Chipster 
        disabled={isDisabled || isLoading}
        onAdd={handleSubmit}
      >
        <Chipster.ItemList />
        <Chipster.Input 
          placeholder={isLoading ? "Saving..." : "Add items..."} 
        />
      </Chipster>
      <button onClick={() => setIsDisabled(!isDisabled)}>
        Toggle Disabled
      </button>
    </div>
  )
}

Important Notes

  • When disabled:
    • Input becomes non-editable
    • Remove buttons are non-clickable
    • Keyboard navigation is disabled
    • Suggestions are hidden
    • All callbacks (onAdd, onRemove) won't fire
  • Visual feedback is provided through opacity and cursor changes
  • The disabled state is propagated to all child components
  • Form submission is prevented when disabled

Common Use Cases

  • Loading states
  • Form submission handling
  • Permission-based access
  • Read-only views
  • Conditional interaction
  • Progressive form completion
  • Rate limiting
  • System maintenance states