Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/helpers/tabs_for/rails/tabs_for_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module TabsFor
module Rails
module TabsForHelper

def tabs_for(object, &block)
content_tag(:ul, class: 'nav nav-tabs', role: 'tablist') do
def tabs_for(object, options={}, &block)
classes = 'nav nav-tabs'
classes = options.delete(:class) if options[:class]

content_tag(:ul, class: classes, role: 'tablist') do
capture TabBuilder.new(object, self), &block
end + content_tag(:div, class: 'tab-content') do
capture PaneBuilder.new(object, self), &block
Expand Down
9 changes: 9 additions & 0 deletions test/tabs_for_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def assert_pane(id, text)
assert_select "div[role=\"tabpanel\"][class=\"tab-pane\"][id=\"#{id}\"]", text: text
end

test "custom class for tabs" do
tabs = tabs_for(object, class: 'tab-header') do |b|
b.tab("Label") { "Content" }
end

concat tabs
assert_select ".tab-header"
end

test "#tab renders tab with translated header with a corresponding pane" do
store_translations(:en, activerecord: {attributes: {project: {name: "Nome"}}}) do
with_concat_tabs_for(object) { |b| b.tab(:name, size: 1) { "Content" } }
Expand Down