SlideShare a Scribd company logo
1 of 95
Download to read offline
Creating a simple, accessible
on/off
switch
Intro
This presentation is based on a
simple GitHub Repo and page
available here:
Checkbox and radio button
switch:
https://russmaxdesign.github.io/switch-checkbox/

Github:
https://github.com/russmaxdesign/switch-
checkbox
During this presentation, I’m going
to ask you some questions - which
you can answer in the chat window.
I'll be giving away three SitePoint
Premium annual memberships as
prizes to the best/quickest
answers.
That gives you unrestricted access
to over $20,000 worth of SitePoint
books and courses!

https://www.sitepoint.com/
premium/
I want to start with a couple of
accessibility-related questions.
And yes, these are incredibly easy,
“prize-winnable” questions.
Question 1:
What is the easiest and most
effective way of identifying common
accessibility problems in your site/
app?
Answer
Unplug the mouse

The easiest and most effective way
to check your site is using
keyboard-only.
A large number of users rely on
key-strokes (TAB, ARROW, ENTER,
SPACE) or the equivalent of these
keystrokes in order to navigate and
interact with sites/apps.
If you cannot navigate or interact
with your site/app using keystrokes
only, then your site is potentially
inaccessible to a large number of
users.
Question 2:
Why is this one of the most evil CSS
rules you could ever write?

*:focus  {  outline:  none;  }
Answer
Because this rule make it hard, if not
impossible, for keyboard-only users
to see which element is in focus
and therefore very hard to navigate
and interact with your site/app.
Time to explore how to style a
simple radio button or checkbox!
Custom radios
& checkboxes
Web designers and developers have
always struggled with how to
customise radio buttons and
checkboxes.
The main issue is that radio buttons
and checkboxes are notoriously
hard to style - especially across
multiple browsers and devices.
In the past, some developers
resorted to JavaScript-based
solutions to solve this problem.
In some cases this involved using
JavaScript to remove the original
radio or checkbox element making
the end result inaccessible for a
wide range of assistive
technologies.
A solution
It is possible to style these elements
without having to use JavaScript.
And more importantly, we can make
the end result accessible.
Let’s take a simple example of an
on/off switch that can be applied to
either radio or checkbox elements:
unchecked
checked
The solution I’m about to demo, has
five key accessibility features.
Well… many of these are not really
features, they are just default
behaviours that should not be
overridden.
Feature 1:
We will use the appropriate
semantic elements - input and label
elements. We will explicitly
associate these elements using
matching “for" and "id" values.
Feature 2:
The label content can be used to
describe the purpose of each switch
for screen readers. This content is
hidden off-screen.
Feature 3:
We will make the two different
states (“on” and “off”) clearly
distinguishable using a tick icon for
the “on” state. This will aid colour-
blind users and some types of
cognitive-impaired users.
(Keeping in mind that we should
never use “color alone” to signal
important information.)
unchecked
checked
Feature 4:
Because we are using native
elements, the default keyboard
behaviour will still be available.
(Users can select a radio button or
checkbox using the SPACE bar).
Feature 5:
We will make the focus and hover
states clearly visible. The focus
state is especially important for
keyboard only users.
checked
checked hover
checked focus
The markup
<div  class="switch">  
    <input  
        class="switch__control"  
        type="radio"  
        name="example01"  
        id="example01">  
    <label  class="switch__label"  for="example01">  
        <span  class="switch__content">Label  content</span>  
    </label>  
</div>
input
label
<div  class="switch">  
    <input  
        class="switch__control"  
        type="radio"  
        name="example01"  
        id="example01">  
    <label  class="switch__label"  for="example01">  
        <span  class="switch__content">Label  content</span>  
    </label>  
</div>
radio
<div  class="switch">  
    <input  
        class="switch__control"  
        type="checkbox"  
        name="example01"  
        id="example01">  
    <label  class="switch__label"  for="example01">  
        <span  class="switch__content">Label  content</span>  
    </label>  
</div>
checkbox
<div  class="switch">  
    <input  
        class="switch__control"  
        type="radio"  
        name="example01"  
        id="example01">  
    <label  class="switch__label"  for="example01">  
        <span  class="switch__content">Label  content</span>  
    </label>  
</div>
id
for
The class
names
We will use BEM-like class names
as these allow us to see the
relationship between the parent
element, descendant elements and
modifiers.
/*  parent  module  */  
.switch  {  }  
/*  parent  modifiers  */  
.switch-­‐-­‐xl  {  }  
.switch-­‐-­‐lg  {  }  
.switch-­‐-­‐md  {  }  
.switch-­‐-­‐sm  {  }  
.switch-­‐-­‐xs  {  }
/*  parent  module  */  
.switch  {  }  
/*  descendants  of  parent  module  */  
.switch__control  {  }  
.switch__label  {  }  
.switch__content  {  }
How does it
work
We can use the parent container
(“switch”) to create the overall
dimensions of the switch.
Parent Container

“switch”
The radio button or checkbox
control (“switch__control”) is then
positioned on top of the parent. It
will be given the same dimensions
as the parent.
Control

“switch__control”
The label (“switch__label”) is placed
on top of the radio button and also
given the same dimensions as the
parent. We are hiding the control
under the label.
We will then style the background
of the label to look like a switch -
including adding rounded corners
and our background icon.
Label

“switch__label”
And finally, the label content
(“switch__content”) is hidden off
screen so that it is available for
screen readers, but does not clutter
the visual appearance of the switch.
Adding states
Checkbox and radio button
elements can be manually changed
by users - from unchecked to
checked etc.
These elements can also be given
predefined boolean “checked” and
“disabled” attributes.
<!-­‐-­‐  no  additional  attributes  -­‐-­‐>  
<input  type="checkbox">  
<!-­‐-­‐  boolean  checked  attribue  -­‐-­‐>  
<input  type="checkbox"  checked>  
<!-­‐-­‐  boolean  disabled  attribute  -­‐-­‐>  
<input  type="checkbox"  disabled>
However, for this solution, most of
the styling is applied to the label
element, rather than the input.
Unfortunately, the label element has
no checked, unchecked or
disabled state of its own.
We can get around this using
adjacent sibling selectors, which
target any label element that is
adjacent to (comes directly after) the
input.
/*  unchecked  input  */  
.switch__control  +  label  {  }  
/*  checked  input  */  
.switch__control:checked  +  label  {  }  
/*  disabled  input  */  
.switch__control[disabled]  +  label  {  }
unchecked
checked
disabled
We also want to style the :focus
and :hover states of the switch,
which can also be done using
adjacent-sibling selectors.
/*  unchecked  input  */  
.switch__control:hover  +  label  {  }  
.switch__control:focus  +  label  {  }  
/*  checked  input  */  
.switch__control:checked:hover  +  label  {  }  
.switch__control:checked:focus  +  label  {  }
unchecked hover
unchecked focus
unchecked
checked
checked hover
checked focus
disabled
SASS variables
Time for our final “prize-winnable”
question (and yes, this one is also
super-easy to answer)…
Question 3:
Why would we want to be able to
control all of the dimensions of our
switch using one master SASS
variable?
Answer
Because this makes it easier to
maintain and to scale as needed.
We can define this one master
variable by dividing our switch into
scalable units.
12x
6x 4x
1x
So, we have four different
variables for the dimensions:

- switch width

- switch height

- toggle width/height

- gutter (space) around the toggle
$switch-­‐width:      3em;  
$switch-­‐height:    ($switch-­‐width  /  2);          /*  1.5em  */  
$toggle-­‐width:      ($switch-­‐width  /  3);            /*  1em  */  
$toggle-­‐gutter:    ($switch-­‐width  /  12);        /*  .25em  */
Now it becomes easy to create a
range of size variations, just by
resetting the font-size.
$switch-­‐xl:    1.6em;  
$switch-­‐lg:    1.4em;  
$switch-­‐md:    1.2em;  
$switch-­‐sm:    1em;  
$switch-­‐xs:    .8em;
We can also set some quick
variables for each of the
background-colors used in
different states.
$color-­‐toggle:                      #fff;  
$color-­‐unchecked-­‐static:  #aaa;  
$color-­‐unchecked-­‐hover:    #777;  
$color-­‐checked-­‐static:      #00a000;  
$color-­‐checked-­‐hover:        #006e00;  
$color-­‐disabled:                  #ddd;
Transitions
I’m generally not a fan of transitions
or animations unless they are being
used to help “tell the story” of a UI
component - help users understand
what is happening.
Transitions should not draw
attention to themselves. Ideally they
should be simple and subtle.
For the checkbox, we could do a
very simple transition to animate
the switch from unchecked to
checked - to help users understand
what has happened.
We can do this by transitioning the
“left” property as it changes from
unchecked to checked.
.switch__label:after  {  
left:  $toggle-­‐gutter;  
transition:  left  .04s;  
}  
.switch__control:checked  +  label:after  {  
    left:  $switch-­‐height  +  $toggle-­‐gutter;  
}
We can also softly animate the
background-color to avoid a jarring
change.
.switch__label  {  
background:  $color-­‐unchecked-­‐static;  
transition:  background  .2s;  
}  
.switch__control:hover  +  label,  
.switch__control:focus  +  label  {  
    background:  $color-­‐unchecked-­‐hover;  
}  
Demos
Checkbox and radio button
switch:
https://russmaxdesign.github.io/switch-checkbox/

Github:
https://github.com/russmaxdesign/switch-
checkbox
A simple, accessible language
switcher module:
https://russmaxdesign.github.io/language-
switcher/

Github:
https://github.com/russmaxdesign/language-
switcher
Upvote - downvote module:
https://russmaxdesign.github.io/upvote-downvote/

Github:
https://github.com/russmaxdesign/upvote-
downvote
Russ Weakley
Max Design
Site: maxdesign.com.au
Twitter: twitter.com/russmaxdesign
Slideshare: slideshare.net/maxdesign
Linkedin: linkedin.com/in/russweakley

More Related Content

What's hot

Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1sunmitraeducation
 
Computer homework
Computer homeworkComputer homework
Computer homeworkadarsh-kaul
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Ppt on visual basics
Ppt on visual basicsPpt on visual basics
Ppt on visual basicsyounganand
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Shashikant Bhongale
 
Documentation For Tab Setup
Documentation For Tab SetupDocumentation For Tab Setup
Documentation For Tab Setupvkeeton
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML formsNadine Cruz
 
Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Shashikant Bhongale
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI ReferenceGauntFace
 
Revit drafting procedure
Revit drafting procedureRevit drafting procedure
Revit drafting procedureAnima M C
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3Faiz Bashir
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3Faiz Bashir
 

What's hot (20)

Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1
 
Computer homework
Computer homeworkComputer homework
Computer homework
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Ppt on visual basics
Ppt on visual basicsPpt on visual basics
Ppt on visual basics
 
Android Button
Android ButtonAndroid Button
Android Button
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16
 
Documentation For Tab Setup
Documentation For Tab SetupDocumentation For Tab Setup
Documentation For Tab Setup
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML forms
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
swingbasics
swingbasicsswingbasics
swingbasics
 
Sencha touch
Sencha touchSencha touch
Sencha touch
 
Knockout in action
Knockout in actionKnockout in action
Knockout in action
 
Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16
 
Intro to Haml
Intro to HamlIntro to Haml
Intro to Haml
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI Reference
 
Developing in android
Developing in androidDeveloping in android
Developing in android
 
Revit drafting procedure
Revit drafting procedureRevit drafting procedure
Revit drafting procedure
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3
 

Viewers also liked

CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreRuss Weakley
 
Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!FITC
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차Michael Yang
 
It's just a Web server - a plea for simplicity
It's just a Web server - a plea for simplicityIt's just a Web server - a plea for simplicity
It's just a Web server - a plea for simplicityBertrand Delacretaz
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차Michael Yang
 
CSS line-height
CSS line-heightCSS line-height
CSS line-heightToby Yun
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차Michael Yang
 
처음부터 다시 배우는 HTML5 & CSS3 1일차
처음부터 다시 배우는 HTML5 & CSS3 1일차처음부터 다시 배우는 HTML5 & CSS3 1일차
처음부터 다시 배우는 HTML5 & CSS3 1일차Michael Yang
 
Router Information Protocol
Router Information ProtocolRouter Information Protocol
Router Information Protocolraysoumik
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing worldRuss Weakley
 
The Staging Server is Dead! Long Live the Staging Server!
The Staging Server is Dead! Long Live the Staging Server!The Staging Server is Dead! Long Live the Staging Server!
The Staging Server is Dead! Long Live the Staging Server!LaunchDarkly
 

Viewers also liked (20)

CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 
Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 9일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 12일차
 
It's just a Web server - a plea for simplicity
It's just a Web server - a plea for simplicityIt's just a Web server - a plea for simplicity
It's just a Web server - a plea for simplicity
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 6일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 11일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 5일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 8일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 10일차
 
CSS line-height
CSS line-heightCSS line-height
CSS line-height
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 7일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료 4일차
 
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차
처음부터 다시 배우는 HTML5 & CSS3 강의자료3일차
 
CSS Reset
CSS ResetCSS Reset
CSS Reset
 
처음부터 다시 배우는 HTML5 & CSS3 1일차
처음부터 다시 배우는 HTML5 & CSS3 1일차처음부터 다시 배우는 HTML5 & CSS3 1일차
처음부터 다시 배우는 HTML5 & CSS3 1일차
 
ENRM 1001 newsletter, Group 9
ENRM 1001 newsletter, Group 9ENRM 1001 newsletter, Group 9
ENRM 1001 newsletter, Group 9
 
Router Information Protocol
Router Information ProtocolRouter Information Protocol
Router Information Protocol
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing world
 
The Staging Server is Dead! Long Live the Staging Server!
The Staging Server is Dead! Long Live the Staging Server!The Staging Server is Dead! Long Live the Staging Server!
The Staging Server is Dead! Long Live the Staging Server!
 

Similar to Creating a Simple, Accessible On/Off Switch

Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascriptambuj pathak
 
Testar2014 presentation
Testar2014 presentationTestar2014 presentation
Testar2014 presentationTanja Vos
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesMalik Tauqir Hasan
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labelsRuss Weakley
 
]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3Klaus Hofeditz
 
Javascript
JavascriptJavascript
Javascripttimsplin
 
Less10 2 e_testermodule_9
Less10 2 e_testermodule_9Less10 2 e_testermodule_9
Less10 2 e_testermodule_9Suresh Mishra
 
Web accessibility - WAI-ARIA a small introduction
Web accessibility - WAI-ARIA a small introductionWeb accessibility - WAI-ARIA a small introduction
Web accessibility - WAI-ARIA a small introductionGeoffroy Baylaender
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011David O'Dowd
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template LanguageGabriel Walt
 
Automate sap security user audit
Automate sap security user auditAutomate sap security user audit
Automate sap security user auditSatyajit Deb
 
Final Project Presentation
Final Project PresentationFinal Project Presentation
Final Project Presentationzroserie
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide Vinay Kumar
 

Similar to Creating a Simple, Accessible On/Off Switch (20)

Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Testar2014 presentation
Testar2014 presentationTestar2014 presentation
Testar2014 presentation
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
 
WPF Controls
WPF ControlsWPF Controls
WPF Controls
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
 
svelte-en.pdf
svelte-en.pdfsvelte-en.pdf
svelte-en.pdf
 
]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3
 
Javascript
JavascriptJavascript
Javascript
 
Java 17
Java 17Java 17
Java 17
 
Less10 2 e_testermodule_9
Less10 2 e_testermodule_9Less10 2 e_testermodule_9
Less10 2 e_testermodule_9
 
Web accessibility - WAI-ARIA a small introduction
Web accessibility - WAI-ARIA a small introductionWeb accessibility - WAI-ARIA a small introduction
Web accessibility - WAI-ARIA a small introduction
 
CRUD with Dojo
CRUD with DojoCRUD with Dojo
CRUD with Dojo
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
 
Chapter 02
Chapter 02Chapter 02
Chapter 02
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
Automate sap security user audit
Automate sap security user auditAutomate sap security user audit
Automate sap security user audit
 
Final Project Presentation
Final Project PresentationFinal Project Presentation
Final Project Presentation
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 

More from Russ Weakley

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windowsRuss Weakley
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptionsRuss Weakley
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible namesRuss Weakley
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?Russ Weakley
 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI componentsRuss Weakley
 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?Russ Weakley
 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design SystemsRuss Weakley
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletesRuss Weakley
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loaderRuss Weakley
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryRuss Weakley
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messagesRuss Weakley
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and ErrorsRuss Weakley
 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?Russ Weakley
 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern LibrariesRuss Weakley
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern librariesRuss Weakley
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Russ Weakley
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-completeRuss Weakley
 
Deep Dive into Line-Height
Deep Dive into Line-HeightDeep Dive into Line-Height
Deep Dive into Line-HeightRuss Weakley
 
Building Accessible Web Components
Building Accessible Web ComponentsBuilding Accessible Web Components
Building Accessible Web ComponentsRuss Weakley
 
Building accessible web components without tears
Building accessible web components without tearsBuilding accessible web components without tears
Building accessible web components without tearsRuss Weakley
 

More from Russ Weakley (20)

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windows
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptions
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible names
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?
 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI components
 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?
 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design Systems
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletes
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loader
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and glory
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messages
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?
 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern Libraries
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern libraries
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-complete
 
Deep Dive into Line-Height
Deep Dive into Line-HeightDeep Dive into Line-Height
Deep Dive into Line-Height
 
Building Accessible Web Components
Building Accessible Web ComponentsBuilding Accessible Web Components
Building Accessible Web Components
 
Building accessible web components without tears
Building accessible web components without tearsBuilding accessible web components without tears
Building accessible web components without tears
 

Recently uploaded

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Recently uploaded (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Creating a Simple, Accessible On/Off Switch

  • 1. Creating a simple, accessible on/off switch
  • 3. This presentation is based on a simple GitHub Repo and page available here:
  • 4. Checkbox and radio button switch: https://russmaxdesign.github.io/switch-checkbox/ Github: https://github.com/russmaxdesign/switch- checkbox
  • 5. During this presentation, I’m going to ask you some questions - which you can answer in the chat window.
  • 6. I'll be giving away three SitePoint Premium annual memberships as prizes to the best/quickest answers.
  • 7. That gives you unrestricted access to over $20,000 worth of SitePoint books and courses! https://www.sitepoint.com/ premium/
  • 8. I want to start with a couple of accessibility-related questions.
  • 9. And yes, these are incredibly easy, “prize-winnable” questions.
  • 10. Question 1: What is the easiest and most effective way of identifying common accessibility problems in your site/ app?
  • 12. Unplug the mouse The easiest and most effective way to check your site is using keyboard-only.
  • 13. A large number of users rely on key-strokes (TAB, ARROW, ENTER, SPACE) or the equivalent of these keystrokes in order to navigate and interact with sites/apps.
  • 14. If you cannot navigate or interact with your site/app using keystrokes only, then your site is potentially inaccessible to a large number of users.
  • 15. Question 2: Why is this one of the most evil CSS rules you could ever write? *:focus  {  outline:  none;  }
  • 17. Because this rule make it hard, if not impossible, for keyboard-only users to see which element is in focus and therefore very hard to navigate and interact with your site/app.
  • 18. Time to explore how to style a simple radio button or checkbox!
  • 20. Web designers and developers have always struggled with how to customise radio buttons and checkboxes.
  • 21.
  • 22. The main issue is that radio buttons and checkboxes are notoriously hard to style - especially across multiple browsers and devices.
  • 23. In the past, some developers resorted to JavaScript-based solutions to solve this problem.
  • 24. In some cases this involved using JavaScript to remove the original radio or checkbox element making the end result inaccessible for a wide range of assistive technologies.
  • 26. It is possible to style these elements without having to use JavaScript. And more importantly, we can make the end result accessible.
  • 27. Let’s take a simple example of an on/off switch that can be applied to either radio or checkbox elements:
  • 29. The solution I’m about to demo, has five key accessibility features.
  • 30. Well… many of these are not really features, they are just default behaviours that should not be overridden.
  • 31. Feature 1: We will use the appropriate semantic elements - input and label elements. We will explicitly associate these elements using matching “for" and "id" values.
  • 32. Feature 2: The label content can be used to describe the purpose of each switch for screen readers. This content is hidden off-screen.
  • 33. Feature 3: We will make the two different states (“on” and “off”) clearly distinguishable using a tick icon for the “on” state. This will aid colour- blind users and some types of cognitive-impaired users.
  • 34. (Keeping in mind that we should never use “color alone” to signal important information.)
  • 36. Feature 4: Because we are using native elements, the default keyboard behaviour will still be available. (Users can select a radio button or checkbox using the SPACE bar).
  • 37. Feature 5: We will make the focus and hover states clearly visible. The focus state is especially important for keyboard only users.
  • 40. <div  class="switch">      <input          class="switch__control"          type="radio"          name="example01"          id="example01">      <label  class="switch__label"  for="example01">          <span  class="switch__content">Label  content</span>      </label>   </div> input label
  • 41. <div  class="switch">      <input          class="switch__control"          type="radio"          name="example01"          id="example01">      <label  class="switch__label"  for="example01">          <span  class="switch__content">Label  content</span>      </label>   </div> radio
  • 42. <div  class="switch">      <input          class="switch__control"          type="checkbox"          name="example01"          id="example01">      <label  class="switch__label"  for="example01">          <span  class="switch__content">Label  content</span>      </label>   </div> checkbox
  • 43. <div  class="switch">      <input          class="switch__control"          type="radio"          name="example01"          id="example01">      <label  class="switch__label"  for="example01">          <span  class="switch__content">Label  content</span>      </label>   </div> id for
  • 45. We will use BEM-like class names as these allow us to see the relationship between the parent element, descendant elements and modifiers.
  • 46. /*  parent  module  */   .switch  {  }   /*  parent  modifiers  */   .switch-­‐-­‐xl  {  }   .switch-­‐-­‐lg  {  }   .switch-­‐-­‐md  {  }   .switch-­‐-­‐sm  {  }   .switch-­‐-­‐xs  {  }
  • 47. /*  parent  module  */   .switch  {  }   /*  descendants  of  parent  module  */   .switch__control  {  }   .switch__label  {  }   .switch__content  {  }
  • 49. We can use the parent container (“switch”) to create the overall dimensions of the switch.
  • 51. The radio button or checkbox control (“switch__control”) is then positioned on top of the parent. It will be given the same dimensions as the parent.
  • 53. The label (“switch__label”) is placed on top of the radio button and also given the same dimensions as the parent. We are hiding the control under the label.
  • 54. We will then style the background of the label to look like a switch - including adding rounded corners and our background icon.
  • 56. And finally, the label content (“switch__content”) is hidden off screen so that it is available for screen readers, but does not clutter the visual appearance of the switch.
  • 58. Checkbox and radio button elements can be manually changed by users - from unchecked to checked etc.
  • 59. These elements can also be given predefined boolean “checked” and “disabled” attributes.
  • 60. <!-­‐-­‐  no  additional  attributes  -­‐-­‐>   <input  type="checkbox">   <!-­‐-­‐  boolean  checked  attribue  -­‐-­‐>   <input  type="checkbox"  checked>   <!-­‐-­‐  boolean  disabled  attribute  -­‐-­‐>   <input  type="checkbox"  disabled>
  • 61. However, for this solution, most of the styling is applied to the label element, rather than the input.
  • 62. Unfortunately, the label element has no checked, unchecked or disabled state of its own.
  • 63. We can get around this using adjacent sibling selectors, which target any label element that is adjacent to (comes directly after) the input.
  • 64. /*  unchecked  input  */   .switch__control  +  label  {  }   /*  checked  input  */   .switch__control:checked  +  label  {  }   /*  disabled  input  */   .switch__control[disabled]  +  label  {  }
  • 66. We also want to style the :focus and :hover states of the switch, which can also be done using adjacent-sibling selectors.
  • 67. /*  unchecked  input  */   .switch__control:hover  +  label  {  }   .switch__control:focus  +  label  {  }   /*  checked  input  */   .switch__control:checked:hover  +  label  {  }   .switch__control:checked:focus  +  label  {  }
  • 70. Time for our final “prize-winnable” question (and yes, this one is also super-easy to answer)…
  • 71. Question 3: Why would we want to be able to control all of the dimensions of our switch using one master SASS variable?
  • 73. Because this makes it easier to maintain and to scale as needed.
  • 74. We can define this one master variable by dividing our switch into scalable units.
  • 76. So, we have four different variables for the dimensions: - switch width - switch height - toggle width/height - gutter (space) around the toggle
  • 77. $switch-­‐width:      3em;   $switch-­‐height:    ($switch-­‐width  /  2);          /*  1.5em  */   $toggle-­‐width:      ($switch-­‐width  /  3);            /*  1em  */   $toggle-­‐gutter:    ($switch-­‐width  /  12);        /*  .25em  */
  • 78. Now it becomes easy to create a range of size variations, just by resetting the font-size.
  • 79. $switch-­‐xl:    1.6em;   $switch-­‐lg:    1.4em;   $switch-­‐md:    1.2em;   $switch-­‐sm:    1em;   $switch-­‐xs:    .8em;
  • 80. We can also set some quick variables for each of the background-colors used in different states.
  • 81. $color-­‐toggle:                      #fff;   $color-­‐unchecked-­‐static:  #aaa;   $color-­‐unchecked-­‐hover:    #777;   $color-­‐checked-­‐static:      #00a000;   $color-­‐checked-­‐hover:        #006e00;   $color-­‐disabled:                  #ddd;
  • 83. I’m generally not a fan of transitions or animations unless they are being used to help “tell the story” of a UI component - help users understand what is happening.
  • 84. Transitions should not draw attention to themselves. Ideally they should be simple and subtle.
  • 85. For the checkbox, we could do a very simple transition to animate the switch from unchecked to checked - to help users understand what has happened.
  • 86. We can do this by transitioning the “left” property as it changes from unchecked to checked.
  • 87.
  • 88. .switch__label:after  {   left:  $toggle-­‐gutter;   transition:  left  .04s;   }   .switch__control:checked  +  label:after  {      left:  $switch-­‐height  +  $toggle-­‐gutter;   }
  • 89. We can also softly animate the background-color to avoid a jarring change.
  • 90. .switch__label  {   background:  $color-­‐unchecked-­‐static;   transition:  background  .2s;   }   .switch__control:hover  +  label,   .switch__control:focus  +  label  {      background:  $color-­‐unchecked-­‐hover;   }  
  • 91. Demos
  • 92. Checkbox and radio button switch: https://russmaxdesign.github.io/switch-checkbox/ Github: https://github.com/russmaxdesign/switch- checkbox
  • 93. A simple, accessible language switcher module: https://russmaxdesign.github.io/language- switcher/ Github: https://github.com/russmaxdesign/language- switcher
  • 94. Upvote - downvote module: https://russmaxdesign.github.io/upvote-downvote/ Github: https://github.com/russmaxdesign/upvote- downvote
  • 95. Russ Weakley Max Design Site: maxdesign.com.au Twitter: twitter.com/russmaxdesign Slideshare: slideshare.net/maxdesign Linkedin: linkedin.com/in/russweakley