diff --git a/lib/claper_web/live/event_live/event_form_component.html.heex b/lib/claper_web/live/event_live/event_form_component.html.heex index b6bc61a..5b01249 100644 --- a/lib/claper_web/live/event_live/event_form_component.html.heex +++ b/lib/claper_web/live/event_live/event_form_component.html.heex @@ -264,6 +264,7 @@ form={f} key={:started_at} name={gettext("Start date and time")} + locale={@current_user.locale} required="true" />

{gettext("Shown in your local time.")}

diff --git a/lib/claper_web/views/components/input_component.ex b/lib/claper_web/views/components/input_component.ex index 96d296e..b5c7dc0 100644 --- a/lib/claper_web/views/components/input_component.ex +++ b/lib/claper_web/views/components/input_component.ex @@ -272,6 +272,7 @@ defmodule ClaperWeb.Component.Input do |> assign_new(:autofocus, fn -> false end) |> assign_new(:placeholder, fn -> false end) |> assign_new(:readonly, fn -> false end) + |> assign_new(:locale, fn -> Gettext.get_locale(ClaperWeb.Gettext) end) |> assign_new(:labelClass, fn -> "text-gray-700" end) |> assign_new(:fieldClass, fn -> "bg-white" end) @@ -286,6 +287,7 @@ defmodule ClaperWeb.Component.Input do readonly: @readonly, autofocus: @autofocus, autocomplete: "off", + lang: @locale, step: 300, class: "input h-12 w-full bg-white px-4 read-only:opacity-50 #{if Keyword.has_key?(@form.errors, @key), do: "input-error", else: ""}" diff --git a/test/claper_web/live/event_live_test.exs b/test/claper_web/live/event_live_test.exs index fa82ccc..628d6ca 100644 --- a/test/claper_web/live/event_live_test.exs +++ b/test/claper_web/live/event_live_test.exs @@ -65,6 +65,16 @@ defmodule ClaperWeb.EventLiveTest do assert has_element?(new_live, ~s(button[form="event-form"]), "Create event") end + test "uses the user's locale for the native date picker", %{user: user} do + {:ok, %{locale: "fr"} = user} = + Claper.Accounts.update_user_preferences(user, %{locale: "fr"}) + + conn = build_conn() |> log_in_user(user) + {:ok, new_live, _html} = live(conn, ~p"/events/new") + + assert has_element?(new_live, ~s(#date-picker input[type="datetime-local"][lang="fr"])) + end + test "adds and removes an unsaved facilitator", %{ conn: conn, presentation_file: presentation_file