initOpen autofocuses on the first element

This commit is contained in:
Tessa Kelly 2020-09-02 10:17:53 -07:00
parent 9a67a64d63
commit 0768862b8b

View File

@ -79,9 +79,16 @@ init =
{-| Pass the id of the element that should receive focus when the modal is closed. {-| Pass the id of the element that should receive focus when the modal is closed.
-} -}
initOpen : String -> Model initOpen : String -> ( Model, Cmd Msg )
initOpen = initOpen returnFocusTo =
Opened ( Opened returnFocusTo, focusFirstElement )
focusFirstElement : Cmd Msg
focusFirstElement =
Dom.focus autofocusId
|> Task.onError (\_ -> Dom.focus firstId)
|> Task.attempt Focused
{-| -} {-| -}
@ -126,11 +133,7 @@ update : { dismissOnEscAndOverlayClick : Bool } -> Msg -> Model -> ( Model, Cmd
update { dismissOnEscAndOverlayClick } msg model = update { dismissOnEscAndOverlayClick } msg model =
case msg of case msg of
OpenModal returnFocusTo -> OpenModal returnFocusTo ->
( Opened returnFocusTo ( Opened returnFocusTo, focusFirstElement )
, Dom.focus autofocusId
|> Task.onError (\_ -> Dom.focus firstId)
|> Task.attempt Focused
)
CloseModal by -> CloseModal by ->
let let