Junior Track Roadmap

Stimulus.js: clipboard controller

This course reads one small Stimulus controller that copies text to the clipboard without a page reload. It covers how data-controller and target attributes connect the class to HTML, and how data-action works in full form and with element default events. It explains the async navigator.clipboard.writeText() call, its secure context requirement, and the deprecated document.execCommand('copy') fallback. It then opens showToast(), which builds a toast from an HTML string and reuses another controller's dismiss behavior. The last lesson reads the three pages that use the controller.

What you'll learn

  • ✓How data-controller and data-*-target attributes connect a Stimulus controller to HTML
  • ✓The full data-action descriptor and Stimulus default events per element
  • ✓How navigator.clipboard.writeText() returns a Promise and needs a secure context
  • ✓Why the deprecated execCommand('copy') fallback depends on a prior .select() call
  • ✓Building a toast from an HTML string and reusing another controller through shared attributes
  • ✓Using the same controller with a visible or a hidden source element
Free preview · Lesson 1 3 min read

Copying without a page reload

A lesson's image manager shows a generated image URL next to a small copy icon. Clicking the icon puts the URL on the clipboard, a toast confirms it, and nothing else on the page moves. No form submits, no request goes to the server, and no Turbo navigation happens. The whole feature lives in one…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...