This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Customize focus styles dynamically as users change interaction styles
version 1.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.0
Committed At 2018-03-16 17:04:06 UTC
elm-lang/mouse 1.0.1 <= v < 2.0.0 1.0.1
elm-lang/keyboard 1.0.1 <= v < 2.0.0 1.0.1
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/dom 1.1.1 <= v < 2.0.0 1.1.1
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

README

Focus Style Manager

What is this and why?

Showing focus styles is vital for users who interact with webpages primarily through keyboard actions.

Focus styles can be confusing/unhelpful for users who interact with applications primarily through point & click.

This library will detect whether the user's last interaction was a keyboard event or mouse event.

Then, it will use this state to display the styles that you specify for this type of user.

Suppose you hate the look of little blue outline that shows around radio inputs when they're focused. You can change the styles so that it's a nice fuschia color for keyboard users, and never shown for point & click users.

How do I use this module?

This library follows the Elm architecture (model passed into the view, user actions trigger updates which change the model... if this isn't familiar, please check out the elm-lang guide.)

Note that the library uses subscriptions rather than Html events to track user events -- be sure to wire those up!

Example Use

Demonstration of behavior

Example Code

import FocusStyleManager

main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }

type alias Model =
    { focusStyleManager : FocusStyleManager.Model
    }

init =
    ( { focusStyleManager = FocusStyleManager.keyboardUser
      }
    , Cmd.none
    )

view model =
    Html.main_ []
        [ FocusStyleManager.style
            { keyboardUser = [ ( "outline", "3px solid pink" ) ]
            , mouseUser = [ ( "outline", "none" ) ]
            }
            model.focusStyleManager
        , Html.text "Probably your application has other content too!"
        ]


type Msg
    = FocusStyleManagerMsg FocusStyleManager.Msg

update msg model =
    case msg of
        FocusStyleManagerMsg focusStyleManagerMsg ->
            let
                focusStyleManager =
                    FocusStyleManager.update focusStyleManagerMsg model.focusStyleManager
            in
            ( { model | focusStyleManager = focusStyleManager }
            , Cmd.none
            )

subscriptions model =
    Sub.map FocusStyleManagerMsg
        (FocusStyleManager.subscriptions model.focusStyleManager)

Note:

The repository contains two examples, one of which is using this module with elm-css. If your application uses elm-css or another styling pre-processor, please be sure to check out the examples folder on github.