Skip to content

Add beforeCopy prop to customize copyText before clipboard action #78

@kadirgun

Description

@kadirgun

Feature Request: beforeCopy Prop for Custom Clipboard Content

Summary:
When using the copy feature, allow developers to intercept and modify the copied content before it is sent to the clipboard, by introducing a beforeCopy function prop.

Motivation:
Currently, the copied value (copyText) is determined internally and cannot be changed by the consumer. In some cases, developers may want to format, sanitize, or otherwise modify the value before it is copied. Providing a hook/prop for this increases flexibility and control for library users.

Proposed API:
Add a new optional prop beforeCopy to the relevant component (e.g., <Copied /> or main JsonView), which receives the computed copyText and returns the new string to be copied. For example:

copyText = beforeCopy ? beforeCopy(copyText) : copyText

Example Usage:

<JsonView.Copied beforeCopy={(text) => text.replace(/\"/g, '')} />

Benefits:

  • Allows custom transformations on copied content
  • Backwards compatible (default: no change)
  • Simple implementation

Labels:

  • enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions