Skip to main content
Elastic UI
Elastic UI
ComponentsPatternsContentData visualization
EUI ChangelogGitHubFigma
  • Guidelines
    • Getting started
    • Accessibility
    • Writing
    • Testing
  • Theming
    • Theme provider
    • Color mode
    • High contrast mode
    • Borders
    • Breakpoints
    • Colors
    • Sizing
    • Typography
  • Templates
    • Page template
    • Sitewide search
  • Layout
    • Accordion
    • Bottom bar
    • Flex
    • Flyout
    • Header
    • Horizontal rule
    • Modal
    • Page components
    • Page header
    • Panel
    • Popover
    • Resizable container
    • Spacer
  • Navigation
    • Breadcrumbs
    • Buttons
    • Collapsible nav
    • Context menu
    • Facet
    • Key pad menu
    • Link
    • Pagination
    • Side nav
    • Steps
    • Tabs
    • Tree view
  • Display
    • Aspect ratio
    • Avatar
    • Badge
    • Callout
    • Card
    • Comment list
    • Description list
    • Drag and drop
    • Empty prompt
    • Health
    • Icons
    • Image
    • List group
    • Loading
    • Progress
    • Skeleton
    • Stat
    • Text
    • Timeline
    • Title
    • Toast
    • Tooltip
    • Tour
  • Forms
    • Form controls
    • Form layouts
    • Form validation
    • Text controls
    • Numeric controls
    • Selection controls
    • Search and filter controls
    • Date and time controls
    • Other controls
  • Tabular content
    • Tables
    • Data grid
  • Editors & Syntax
    • Code
    • Markdown
  • Utilities
    • Accessibility
    • Auto sizer
    • Beacon
    • Color palettes
    • Copy
    • CSS utility classes
    • Delay
    • Error boundary
    • Focus trap
    • Highlight and mark
    • HTML ID generator
    • I18n
    • Inner text
    • Mutation observer
    • Outside click detector
    • Overlay mask
    • Portal
    • Pretty duration
    • Provider
    • Resize observer
    • Scroll
    • Text diff
    • Text truncation
    • Window events
  • EUI
  • Utilities
  • Text diff

Text diff

The hook, useEuiTextDiff, generates a set of changes between two strings. It returns both React elements for displaying the diff and an object representing the identified changes. The timeout prop is used to set how many seconds any diff's exploration phase may take. The default value is 0.1, a value of 0 disables the timeout and lets diff run until completion. The higher the timeout, the more detailed the comparison.

const [rendered, textDiffObject] = useEuiTextDiff({ beforeText, afterText });

Loading...

Custom rendered elements

By default, the hook will wrap deletions with <del> and insertions with <ins> elements. You can replace these elements with the deleteComponent and insertComponent props respectively.

Also, since rendered is simple html string, you can wrap it in any contextual element like

EuiText or EuiCodeBlock.

Loading...

Props

useEuiTextDiff

Extends HTMLAttributes
𐘂𐘂
✄𐘗✄𐘗
Prop
↦
Description and type
↦
Default value
↵
Prop
className#
↦
Description and type
Type: string
↦
Default value
↵
Prop
aria-label#
↦
Description and type

Defines a string value that labels the current element.
@see aria-labelledby.

Type: string
↦
Default value
↵
Prop
data-test-subj#
↦
Description and type
Type: string
↦
Default value
↵
Prop
css#
↦
Description and type
Type: Interpolation<Theme>
↦
Default value
↵
Prop
beforeText#
↦
Description and type

The starting string

Type: string
↦
Default value
↵
Prop
afterText#
↦
Description and type

The string used to compare against beforeText

Type: string
↦
Default value
↵
Prop
insertComponent#
↦
Description and type

HTML element to wrap insertion differences.
Defaults to ins

Type: ElementType
↦
Default value
ins
↵
Prop
deleteComponent#
↦
Description and type

HTML element to wrap deletion differences.
Defaults to del

Type: ElementType
↦
Default value
del
↵
Prop
sameComponent#
↦
Description and type

HTML element to wrap text with no differences.
Doesn't wrap with anything by default

Type: ElementType
↦
Default value
↵
Prop
timeout#
↦
Description and type

Time in milliseconds. Passing a timeout of value '0' disables the timeout state

Type: number
↦
Default value
0.1
↵
𐘂𐘂
Edit this page

Previous
Scroll
Next
Text truncation
  • Custom rendered elements
  • Props
EUI is dual-licensed under Elastic License 2.0 and Server Side Public License, v 1 | Crafted with ❤ by Elastic