rundis / elm-bootstrap

Responsive and reliable web apps with Elm and Twitter Bootstrap
http://elm-bootstrap.info/
BSD 3-Clause "New" or "Revised" License
398 stars 72 forks source link

No option to hide the NavBar Menu after Clicking a Menu item #181

Closed jarlah closed 4 years ago

jarlah commented 4 years ago

Standard setup. When clicking NavBar item. New page is displayed But NavBar is still expanded. Is this NavBar only meant for like Elm apps where page is initialized on page load ?

jarlah commented 4 years ago

I think a hack would be to reinit the NavBar when i click a link. But is it a good work around ? Nope

jarlah commented 4 years ago

it actually works wonderful (the hack), but shall I give it a try to suggest a better way for how to handle this?

jarlah commented 4 years ago

The "hack":

        ( ClickedLink urlRequest, _ ) ->
            case urlRequest of
                Browser.Internal url ->
                    case url.fragment of
                        Just _ ->
                            -- If we got a link that included a fragment,
                            -- we ignore this url change, because we dont care about hash urls
                            ( model, Cmd.none )

                        Nothing ->
                            let
                                ( newNavState, newNavCmd ) =
                                    Navbar.initialState NavbarMsg
                            in
                            ( { model | navState = newNavState }
                            , Cmd.batch [ newNavCmd, Nav.pushUrl (Session.navKey (toSession model.page)) (Url.toString url) ]
                            )

                Browser.External href ->
                    ( model
                    , Nav.load href
                    )