Skip to content
Merged
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
27 changes: 17 additions & 10 deletions app/components/alchemy/admin/locale_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ module Alchemy
module Admin
# Renders a locale select tag for switching the backend locale.
class LocaleSelect < ViewComponent::Base
attr_reader :name
attr_reader :name, :auto_submit

def initialize(name = :admin_locale)
def initialize(name = :admin_locale, auto_submit: true)
@name = name
@auto_submit = auto_submit
end

def call
form_tag(helpers.url_for, method: :get) do
content_tag("alchemy-auto-submit") do
select_tag(
name,
options_for_select(
translations_for_select,
::I18n.locale
)
)
if auto_submit
content_tag("alchemy-auto-submit", locale_select)
else
locale_select
end
end
end
Expand All @@ -28,6 +25,16 @@ def render?

private

def locale_select
select_tag(
name,
options_for_select(
translations_for_select,
::I18n.locale
)
)
end

def available_locales
@_available_locales ||= Alchemy::I18n.available_locales.sort!
end
Expand Down
13 changes: 13 additions & 0 deletions spec/components/alchemy/admin/locale_select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,18 @@
expect(page).to have_selector("select[name='language']")
end
end

it "should return a select with auto submit wrapper" do
expect(page).to have_selector("alchemy-auto-submit select[name='admin_locale']")
end

context "with auto_submit false" do
let(:render) { render_inline described_class.new(:admin_locale, auto_submit: false) }

it "should return a select without auto submit wrapper" do
expect(page).not_to have_selector("alchemy-auto-submit")
expect(page).to have_selector("select[name='admin_locale']")
end
end
end
end
Loading