Modal Components
Dialog boxes that appear on top of the main content. Perfect for confirmations, forms, alerts, and focused user interactions.
Installation
1. Stimulus Controller Setup
Start by adding the following controller to your project:
This code is available to Pro users only.
// Hey curious person!
// You seem to be sneaking around the code...
// I hope you're enjoying the components!
// Have a great day!
class SecretMessage {
constructor() {
this.message = "Thanks for checking out Rails Blocks!";
this.compliment = "You're awesome!";
}
reveal() {
console.log(this.message);
return this.compliment;
}
}
const secret = new SecretMessage();
secret.reveal();
2. Custom CSS
Here are the custom CSS classes that we used on Rails Blocks to style the modal components. You can copy and paste these into your own CSS file to style & personalize your modals. This is the same CSS applied to the slideover components.
This code is available to Pro users only.
/* Hey curious person! */
/* You seem to be sneaking around the code... */
/* I hope you're enjoying the components! */
/* Have a great day! */
.secret-message {
/* Thanks for checking out Rails Blocks! */
opacity: 0.7;
transform: scale(0.95);
filter: blur(2px);
}
.awesome-btn:hover {
/* You're awesome! */
animation: wiggle 0.5s ease-in-out;
}
Examples
Basic Modal
A simple modal with a trigger button, content, and actions.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Confirm Modal
A confirmation modal typically used for destructive actions. This modal prevents the user from closing it by clicking the backdrop or pressing the escape key.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Modal Sizes
Modals come in various sizes: small, medium, large, extra large, and more.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Fullscreen Modal
A modal that takes up the entire viewport.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Modal with Form
A modal containing a form for user input.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Modal without Close Button
A modal that can only be closed via action buttons.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Lazy Loading Modal
A modal that loads its content only when opened, improving performance for heavy content. Uses data-modal-lazy-load-value="true"
.
Heavy Content Loaded
This content was loaded only when you opened the modal. This is useful for performance when you have heavy content like:
- Large forms with many fields
- Data tables with lots of rows
- Rich media content like videos or galleries
- Complex components that take time to render
Example: User Settings Form
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Turbo Modal
A modal that loads content from the server using Turbo Frames. Uses data-modal-lazy-load-value="true"
& data-modal-turbo-frame-src-value="<%= modal_content_path %>"
.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
This code is available to Pro users only.
# Hey curious person!
# You seem to be sneaking around the code...
# I hope you're enjoying the components!
# Have a great day!
class SecretMessage
def initialize
@message = "Thanks for checking out Rails Blocks!"
@compliment = "You're awesome!"
end
def reveal
puts @message
@compliment
end
end
secret = SecretMessage.new
secret.reveal
This code is available to Pro users only.
# Hey curious person!
# You seem to be sneaking around the code...
# I hope you're enjoying the components!
# Have a great day!
class SecretMessage
def initialize
@message = "Thanks for checking out Rails Blocks!"
@compliment = "You're awesome!"
end
def reveal
puts @message
@compliment
end
end
secret = SecretMessage.new
secret.reveal
Nested Modals
A modal that can open another modal from within it. Useful for multi-step processes or confirmations within modals.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Configuration
The modal component is powered by a Stimulus controller that provides smooth animations, backdrop click handling, and Turbo integration.
HTML Structure
Basic modal structure with required data attributes:
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Lazy Loading
Enable lazy loading to improve performance by loading content only when the modal is opened:
Template-based Lazy Loading
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Turbo Frame Lazy Loading
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>π Hello, Code Detective! π΅οΈ</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! π</small></p>
</div>
<footer>
<p>Built with β€οΈ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("π Bonus points for opening the console!");
console.log("Keep exploring and happy coding! π»");
</script>
</body>
</html>
Configuration Values
Prop | Description | Type | Default |
---|---|---|---|
open
|
Controls whether the modal is open on initial load |
Boolean
|
false
|
lazyLoad
|
Whether to load modal content only when opened |
Boolean
|
false
|
turboFrameSrc
|
URL for Turbo Frame lazy loading |
String
|
""
|
preventDismiss
|
Whether to prevent the modal from being dismissed |
Boolean
|
false
|
Targets
Target | Description | Required |
---|---|---|
dialog
|
The dialog element that contains the modal content | Required |
template
|
Template element for lazy loading content | Optional |
Actions
Action | Description | Usage |
---|---|---|
open
|
Opens the modal as a modal dialog |
data-action="click->modal#open:prevent"
|
close
|
Closes the modal with animations |
data-action="click->modal#close:prevent"
|
backdropClose
|
Closes the modal when clicking outside the content |
data-action="mousedown->modal#backdropClose"
|
show
|
Shows the dialog non-modally (for special use cases) |
data-action="click->modal#show"
|
hide
|
Alias for close method |
data-action="click->modal#hide"
|
Modal Sizes
Different modal sizes can be achieved by changing the max-w-*
class on the dialog element:
Size | Class | Description |
---|---|---|
Small |
max-w-sm
|
Perfect for brief confirmations or simple messages |
Medium (Default) |
max-w-md
|
Works well for most content types |
Large |
max-w-lg
|
More space for complex forms or detailed content |
Extra Large |
max-w-xl
|
Substantial space for data tables or multi-step forms |
2XL |
max-w-2xl
|
Even more space for extensive content |
3XL |
max-w-3xl
|
Maximum width while maintaining margins |
Fullscreen |
max-w-full max-h-full
|
Takes up the entire viewport |
Key Features
- Native Dialog Element: Uses the HTML dialog element for better accessibility and browser support
- Smooth Animations: Scale and fade animations with closing state handling
- Backdrop Click: Closes when clicking outside the modal content
- Turbo Integration: Automatically closes before Turbo caches the page
- Body Scroll Lock: Prevents body scrolling when modal is open
- Multiple Sizes: From small to fullscreen, with responsive design
- Lazy Loading: Load content only when modal is opened for better performance
- Turbo Frame Support: Load modal content from server using Turbo Frames
Accessibility Features
- Focus Management: Uses native dialog focus trapping
- Screen Reader Support: Proper ARIA attributes with close button labels
- Keyboard Navigation: ESC key closes the modal (native dialog behavior)
- Semantic Markup: Uses the native dialog element for proper semantics
Usage Notes
-
The dialog element must have the
modal
class for proper styling -
Use
:prevent
modifier on actions to prevent default link/button behavior - The controller handles animation cleanup to ensure smooth closing transitions
-
For Rails forms with Turbo, consider using
data-turbo-frame="_top"
on the form - To hide the close button, simply omit it from the HTML structure