1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

ui: Add button to open recent menu via keyboard

This commit is contained in:
James Hillyerd
2019-02-15 19:50:46 -08:00
parent b82cafc338
commit d933d591d8
3 changed files with 67 additions and 15 deletions

View File

@@ -30,14 +30,16 @@ type Page
type alias FrameControls msg = type alias FrameControls msg =
{ viewMailbox : String -> msg { menuVisible : Bool
, toggleMenu : msg
, recentVisible : Bool
, showRecent : Bool -> msg
, viewMailbox : String -> msg
, mailboxOnInput : String -> msg , mailboxOnInput : String -> msg
, mailboxValue : String , mailboxValue : String
, recentOptions : List String , recentOptions : List String
, recentActive : String , recentActive : String
, clearFlash : msg , clearFlash : msg
, showMenu : Bool
, toggleMenu : msg
} }
@@ -50,7 +52,7 @@ frame controls session activePage modal content =
[ i [ class "fas fa-bars" ] [] ] [ i [ class "fas fa-bars" ] [] ]
, span [ class "navbar-brand" ] , span [ class "navbar-brand" ]
[ a [ Route.href Route.Home ] [ text "@ inbucket" ] ] [ a [ Route.href Route.Home ] [ text "@ inbucket" ] ]
, ul [ classList [ ( "main-nav", True ), ( "active", controls.showMenu ) ] ] , ul [ class "main-nav", classList [ ( "active", controls.menuVisible ) ] ]
[ if session.config.monitorVisible then [ if session.config.monitorVisible then
navbarLink Monitor Route.Monitor [ text "Monitor" ] activePage navbarLink Monitor Route.Monitor [ text "Monitor" ] activePage
@@ -137,6 +139,7 @@ navbarLink page route linkContent activePage =
navbarRecent : Page -> FrameControls msg -> Html msg navbarRecent : Page -> FrameControls msg -> Html msg
navbarRecent page controls = navbarRecent page controls =
let let
-- Active means we are viewing a specific mailbox.
active = active =
page == Mailbox page == Mailbox
@@ -156,13 +159,41 @@ navbarRecent page controls =
else else
controls.recentOptions controls.recentOptions
dropdownExpanded =
if controls.recentVisible then
"true"
else
"false"
recentLink mailbox = recentLink mailbox =
a [ Route.href (Route.Mailbox mailbox) ] [ text mailbox ] a [ Route.href (Route.Mailbox mailbox) ] [ text mailbox ]
in in
li li
[ class "navbar-recent" [ class "navbar-recent navbar-dropdown"
, classList [ ( "navbar-dropdown", True ), ( "navbar-active", active ) ] , classList [ ( "navbar-active", active ) ]
, attribute "aria-haspopup" "true"
, ariaExpanded controls.recentVisible
, Events.onMouseOver (controls.showRecent True)
, Events.onMouseOut (controls.showRecent False)
] ]
[ span [ class "navbar-active-bg" ] [ text title ] [ span [ class "navbar-active-bg" ]
[ text title
, button
[ class "navbar-dropdown-button"
, Events.onClick (controls.showRecent (not controls.recentVisible))
]
[ i [ class "fas fa-chevron-down" ] [] ]
]
, div [ class "navbar-dropdown-content" ] (List.map recentLink recentMailboxes) , div [ class "navbar-dropdown-content" ] (List.map recentLink recentMailboxes)
] ]
ariaExpanded : Bool -> Attribute msg
ariaExpanded value =
attribute "aria-expanded" <|
if value then
"true"
else
"false"

View File

@@ -25,7 +25,8 @@ import Url exposing (Url)
type alias Model = type alias Model =
{ page : PageModel { page : PageModel
, mailboxName : String , mailboxName : String
, showMenu : Bool , menuVisible : Bool
, recentVisible : Bool
} }
@@ -64,7 +65,8 @@ init configValue location key =
initModel = initModel =
{ page = Home subModel { page = Home subModel
, mailboxName = "" , mailboxName = ""
, showMenu = False , menuVisible = False
, recentVisible = False
} }
route = route =
@@ -85,6 +87,7 @@ type Msg
| OnMailboxNameInput String | OnMailboxNameInput String
| ViewMailbox String | ViewMailbox String
| ToggleMenu | ToggleMenu
| ShowRecent Bool
| HomeMsg Home.Msg | HomeMsg Home.Msg
| MailboxMsg Mailbox.Msg | MailboxMsg Mailbox.Msg
| MonitorMsg Monitor.Msg | MonitorMsg Monitor.Msg
@@ -217,7 +220,10 @@ updateMain msg model session =
) )
ToggleMenu -> ToggleMenu ->
( { model | showMenu = not model.showMenu }, Cmd.none ) ( { model | menuVisible = not model.menuVisible }, Cmd.none )
ShowRecent visible ->
( { model | recentVisible = visible }, Cmd.none )
_ -> _ ->
updatePage msg model updatePage msg model
@@ -256,7 +262,7 @@ changeRouteTo route model =
getSession model getSession model
newModel = newModel =
{ model | showMenu = False } { model | menuVisible = False, recentVisible = False }
in in
case route of case route of
Route.Unknown path -> Route.Unknown path ->
@@ -373,14 +379,16 @@ view model =
"" ""
controls = controls =
{ viewMailbox = ViewMailbox { menuVisible = model.menuVisible
, toggleMenu = ToggleMenu
, recentVisible = model.recentVisible
, showRecent = ShowRecent
, viewMailbox = ViewMailbox
, mailboxOnInput = OnMailboxNameInput , mailboxOnInput = OnMailboxNameInput
, mailboxValue = model.mailboxName , mailboxValue = model.mailboxName
, recentOptions = session.persistent.recentMailboxes , recentOptions = session.persistent.recentMailboxes
, recentActive = mailbox , recentActive = mailbox
, clearFlash = ClearFlash , clearFlash = ClearFlash
, showMenu = model.showMenu
, toggleMenu = ToggleMenu
} }
framePage : framePage :

View File

@@ -43,11 +43,16 @@
text-decoration: none; text-decoration: none;
} }
/* This takes precendence over .navbar a above */
.navbar-brand a { .navbar-brand a {
display: inline-block; display: inline-block;
padding: 12px 15px; padding: 12px 15px;
} }
.navbar-dropdown-button {
display: none;
}
.navbar li { .navbar li {
color: var(--navbar-color); color: var(--navbar-color);
} }
@@ -131,6 +136,14 @@ li.navbar-active span,
margin-top: 1px; margin-top: 1px;
} }
.navbar-dropdown-button {
background: none;
border: none;
color: var(--navbar-color);
display: inline;
padding-right: 0;
}
.navbar-dropdown-content { .navbar-dropdown-content {
background-color: var(--bg-color); background-color: var(--bg-color);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@@ -143,7 +156,7 @@ li.navbar-active span,
z-index: 1; z-index: 1;
} }
.navbar-dropdown:hover .navbar-dropdown-content { .navbar-dropdown[aria-expanded="true"] .navbar-dropdown-content {
display: block; display: block;
} }