In my Rails 7 app I've got CustomersController
where inside there is show action with the corresponding show.slim
view. Inside this view I want to have 2 tabs:
- "Data", with text of "This is data page" - this tab should be active after user hits show.slim
- "Customer Users", with text of "Here is the list of Customer Users".
When user hits show url (customer_path) he should be able to see Data tab as active and after click "Customer Users" he/she should not be redirected anyway but stays at the page and the text of "Here is the list of Customer Users" should be rendered. I want to use turbo-frame to control tabs switching, no extra JS needed. I'm using tailwindcss.
So what I did is that:
customers/show.slim
:
div.tabs
button.tab-button[data-turbo-frame="customer_data" data-turbo-frame-target="data"] Data
button.tab-button[data-turbo-frame="customer_users" data-turbo-frame-target="users"] Customer Users
= turbo_frame_tag "data" do
h1 Data
p This is data page
= turbo_frame_tag "users" do
h1 Customer Users
p Here is the list of Customer Users
With some extra css:
.tab-button {
@apply inline-block py-2 px-4 border-b-2 font-medium text-sm focus:outline-none transition duration-150 ease-in-out;
}
.tab-button.active {
@apply border-indigo-500 text-gray-900;
}
.tab-button:hover:not(.active) {
@apply border-indigo-500 text-gray-900;
}
.tabs {
@apply border-b border-gray-200 px-4 flex justify-start;
}
Instead I'm getting this view:
Like I said, at the first glance I want to understand what should be done to make it work? It has to be turbo-frame because EOD I'll have few view components for that.