Skip to content

Font Family ​

This is the Font Family extension. It allows you to change the font family of text in the editor.

Default Usage ​

Default usage of the font family extension and its control button.

Vue
html
<template>
  <HLTextEditor :editor="editor">
    <template #header>
      <RTEControlFontFamily :editor="editor" />
    </template>
    <template #footer>
      <div>Footer</div>
    </template>
  </HLTextEditor>
</template>
<script setup lang="ts">
  import { ref } from 'vue'
  import {
    RequiredExtensions,
    Editor,
    HLTextEditor,
    RTEControlFontFamily,
    FontFamily,
    TextStyle,
  } from '@platform-ui/rte'

  const content = ref()
  const HTML = ref()

  const editor = new Editor({
    content: 'Select text and change the font family',
    extensions: [FontFamily, TextStyle, RequiredExtensions.configure({})],
    onUpdate({ editor }) {
      content.value = editor.getText()
      HTML.value = editor.getHTML()
    },
  })
</script>

Custom Font Family Options ​

You can provide custom font family options to the control.

Vue
html
<template>
  <HLTextEditor :editor="editor">
    <template #header>
      <RTEControlFontFamily
        :editor="editor"
        :fontFamilyOptions="customFontFamilyOptions"
        fallbackFont="Impact"
      />
    </template>
  </HLTextEditor>
</template>
<script setup lang="ts">
  import { ref } from 'vue'
  import {
    RequiredExtensions,
    Editor,
    HLTextEditor,
    RTEControlFontFamily,
    FontFamily,
    TextStyle,
  } from '@platform-ui/rte'

  const customFontFamilyOptions = [
    {
      label: h('div', { style: { fontFamily: 'Arial' } }, 'Arial'),
      key: 'Arial',
    },
    {
      label: h('div', { style: { fontFamily: 'Courier New' } }, 'Courier New'),
      key: 'Courier New',
    },
    {
      label: h('div', { style: { fontFamily: 'Georgia' } }, 'Georgia'),
      key: 'Georgia',
    },
    {
      label: h(
        'div',
        { style: { fontFamily: 'Times New Roman' } },
        'Times New Roman'
      ),
      key: 'Times New Roman',
    },
    {
      label: h('div', { style: { fontFamily: 'Verdana' } }, 'Verdana'),
      key: 'Verdana',
    },
  ]

  const editor = new Editor({
    content: 'Select text and change the font family',
    extensions: [FontFamily, TextStyle, RequiredExtensions.configure({})],
    onUpdate({ editor }) {
      content.value = editor.getText()
      HTML.value = editor.getHTML()
    },
  })
</script>

Fallback Font ​

You can set a fallback font that will be used as the default font family.

Vue
html
<HLTextEditor :editor="editor">
  <template #header>
    <RTEControlFontFamily :editor="editor" fallbackFont="Georgia" />
  </template>
</HLTextEditor>

Filterable ​

Enable search/filter functionality in the font family dropdown.

Vue
html
<template>
  <HLTextEditor :editor="editor">
    <template #header>
      <RTEControlFontFamily :editor="editor" :filterable="true" />
    </template>
  </HLTextEditor>
</template>
<script setup lang="ts">
  import { ref } from 'vue'
  import {
    RequiredExtensions,
    Editor,
    HLTextEditor,
    RTEControlFontFamily,
    FontFamily,
    TextStyle,
  } from '@platform-ui/rte'

  const editor = new Editor({
    content: 'Select text and change the font family',
    extensions: [FontFamily, TextStyle, RequiredExtensions.configure({})],
    onUpdate({ editor }) {
      content.value = editor.getText()
      HTML.value = editor.getHTML()
    },
  })
</script>

Commands ​

js
// Set font family
editor?.chain().focus().setFontFamily('Arial').run()

Imports ​

ts
import {
  RequiredExtensions,
  Editor,
  HLTextEditor,
  RTEControlFontFamily,
  FontFamily,
  TextStyle,
} from '@platform-ui/rte'

Props ​

PropTypeDefaultDescription
editor *Editor-The editor instance
fallbackFontstring'Inter'The default font family
fontFamilyOptionsArray<{label: string | VNode, key: string}>undefinedCustom font family options
filterablebooleanfalseEnable search/filter in dropdown
classNamestring''Additional CSS class name
languageLanguage'en-US'The language for localization
tostring | HTMLElementundefinedTarget element for dropdown portal
ariaLabelstringnullAccessibility label

Events ​

EventPayloadDescription
update:valuestringEmitted when font family is changed

Slots ​

SlotDescriptionDefault
labelThe label displayed in dropdownCapitalized selected font family