# Titre {#heading}

Source: [Ajouter des titres H1 à H6 dans l’éditeur React · Yurich](https://leeyujoo.com/yurich/fr/features/heading/)

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

Package version: `0.1.2`

Transformez un paragraphe en titre H1 à H6.

## Essayez {#try-it}

Dans « Créez votre barre d’outils », cliquez sur **Titre 2** pour obtenir `<h2>Créez votre barre d’outils</h2>`. Cliquez sur **Paragraphe** pour revenir au paragraphe.

## Ajoutez la fonctionnalité à l’éditeur {#setup}

Activez `Heading` et passez à `setHeading` un niveau de 1 à 6.

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

export function HeadingEditor() {
  const editor = useEditor({
    extensions: [Heading],
    initialValue: "<p>Créez votre barre d’outils</p>" + "<p>Commencez par ajouter un bouton Gras.</p>",
  });
  const isH2 = useIsActive(editor, 'setHeading', 2);

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="Titres">
        <button
          type="button"
          aria-pressed={isH2}
          onMouseDown={event => event.preventDefault()}
          onClick={() => editor.execute('setHeading', 2)}
        >
          Titre 2
        </button>
        <button
          type="button"
          onMouseDown={event => event.preventDefault()}
          onClick={() => editor.execute('removeHeading')}
        >
          Paragraphe
        </button>
      </div>
      <EditorContent ariaLabel="Éditeur" />
    </EditorProvider>
  );
}
```

## Comportement à connaître {#behavior}

La commande peut s’appliquer à plusieurs blocs. Un élément de liste transformé en titre quitte la liste.

[Fonctionnalités](https://leeyujoo.com/yurich/fr/features/)
