# Tautan {#link}

Source: [Tambahkan dan hapus tautan di editor React · Yurich](https://leeyujoo.com/yurich/id/features/link/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Tambahkan tautan pada pilihan atau posisi kursor.

## Coba sendiri {#try-it}

Pilih “panduan format”, klik **Tambah tautan**, dan masukkan `https://example.com`. Dari dalam tautan, klik **Hapus tautan** untuk menghapusnya.

## Tambahkan ke editor {#setup}

Aktifkan `Link`, lalu panggil `editor.execute('setLink', { href })`. Contoh mempertahankan pilihan saat meminta URL.

```tsx
import { EditorContent, EditorProvider, Link, useEditor, useIsActive } from 'yurich';

export function LinkEditor() {
  const editor = useEditor({
    extensions: [Link],
    initialValue: "<p>Baca panduan format sebelum mencoba semua tombol.</p>",
  });
  const active = useIsActive(editor, 'link');

  function addLink() {
    const href = window.prompt("URL tautan", 'https://example.com');
    if (href) editor.execute('setLink', { href });
  }

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="Tautan">
        <button
          type="button"
          onMouseDown={event => event.preventDefault()}
          onClick={addLink}
        >
          Tambah tautan
        </button>
        <button
          type="button"
          disabled={!active}
          onMouseDown={event => event.preventDefault()}
          onClick={() => editor.execute('removeLink')}
        >
          Hapus tautan
        </button>
      </div>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Perilaku yang perlu diperhatikan {#behavior}

Gunakan `http://`, `https://`, atau `mailto:`. Tanpa pilihan, URL menjadi teks tautan.

[Fitur](https://leeyujoo.com/yurich/id/features/)
