class Primer::Beta::ClipboardCopy
Always set an accessible label to help the user interact with the component.
@accessibility
Use ‘ClipboardCopy` to copy element text content or input values to the clipboard.
def before_render
def before_render validate_aria_label if content.blank? end
def initialize(value: nil, **system_arguments)
-
system_arguments(Hash) -- <%= link_to_system_arguments_docs %> -
for(String) -- Element id from where to get the copied value. -
value(String) -- Text to copy into the users clipboard when they click the component. -
aria-label(String) -- String that will be read to screenreaders when the component is focused
Other tags:
- Example: Copying from an element -
Example: With text instead of icons -
Example: Default -
def initialize(value: nil, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @value = value validate! @system_arguments[:tag] = "clipboard-copy" @system_arguments[:value] = value if value.present? end
def validate!
def validate! raise ArgumentError, "Must provide either `value` or `for`" if @value.nil? && @system_arguments[:for].nil? end