File tree Expand file tree Collapse file tree 2 files changed +30
-10
lines changed
app/components/alchemy/admin
spec/components/alchemy/admin Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,19 @@ module Alchemy
22 module Admin
33 # Renders a locale select tag for switching the backend locale.
44 class LocaleSelect < ViewComponent ::Base
5- attr_reader :name
5+ attr_reader :name , :auto_submit
66
7- def initialize ( name = :admin_locale )
7+ def initialize ( name = :admin_locale , auto_submit : true )
88 @name = name
9+ @auto_submit = auto_submit
910 end
1011
1112 def call
1213 form_tag ( helpers . url_for , method : :get ) do
13- content_tag ( "alchemy-auto-submit" ) do
14- select_tag (
15- name ,
16- options_for_select (
17- translations_for_select ,
18- ::I18n . locale
19- )
20- )
14+ if auto_submit
15+ content_tag ( "alchemy-auto-submit" , locale_select )
16+ else
17+ locale_select
2118 end
2219 end
2320 end
@@ -28,6 +25,16 @@ def render?
2825
2926 private
3027
28+ def locale_select
29+ select_tag (
30+ name ,
31+ options_for_select (
32+ translations_for_select ,
33+ ::I18n . locale
34+ )
35+ )
36+ end
37+
3138 def available_locales
3239 @_available_locales ||= Alchemy ::I18n . available_locales . sort!
3340 end
Original file line number Diff line number Diff line change 3333 expect ( page ) . to have_selector ( "select[name='language']" )
3434 end
3535 end
36+
37+ it "should return a select with auto submit wrapper" do
38+ expect ( page ) . to have_selector ( "alchemy-auto-submit select[name='admin_locale']" )
39+ end
40+
41+ context "with auto_submit false" do
42+ let ( :render ) { render_inline described_class . new ( :admin_locale , auto_submit : false ) }
43+
44+ it "should return a select without auto submit wrapper" do
45+ expect ( page ) . not_to have_selector ( "alchemy-auto-submit" )
46+ expect ( page ) . to have_selector ( "select[name='admin_locale']" )
47+ end
48+ end
3649 end
3750end
You can’t perform that action at this time.
0 commit comments