close
The Wayback Machine - https://web.archive.org/web/20140717065647/https://github.com/twbs/bootstrap/pull/13907
Skip to content
This repository

add "focus" to focused btns with button plugin #13907

Merged
merged 1 commit into from 10 days ago

4 participants

Jacob Heinrich Fenkart Mark Otto Chris Rebert
Jacob
Owner
fat commented

possible solution for #12145.

bit tired tho so might have missed something…

similar to @hnrch02 – except uses focus/blur instead of focusin/focusout. I was going to use the latter, but read firefox doesn't support them (https://developer.mozilla.org/en-US/docs/Web/Events/focusout)… and this appears to work, even though i thought they didn't bubble :eyes: weird.

went back and forth with toggle class, but ultimately thought it might be safer to tie specific events to specific actions

Chris Rebert cvrebert commented on the diff
js/button.js
((13 lines not shown))
100 109 // BUTTON DATA-API
101 110 // ===============
102 111
103   - $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
104   - var $btn = $(e.target)
105   - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
106   - Plugin.call($btn, 'toggle')
107   - e.preventDefault()
108   - })
  112 + $(document)
  113 + .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
2
Chris Rebert Owner
cvrebert added a note

Why is/was it ^= as opposed to =?

Heinrich Fenkart
hnrch02 added a note

Because of button groups, they toggle via data-toggle="buttons".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Heinrich Fenkart

I guess we can't do much at this time about the disability to focus radio inputs, right?

Jacob
Owner
fat commented

@hnrch02 huh? don't follow sorry?

Heinrich Fenkart

@fat Try to tab to Radio 2 in this Bin.

Heinrich Fenkart

This needs the styles for .focus, BTW. /cc @mdo

Mark Otto
Owner
mdo commented

@hnrch02 I'll add the styles if necessary once the JS works across the board. That jsbin you linked to still wasn't working for me. I do see a focus state now though, just not on all those radio buttons.

Heinrich Fenkart

@mdo Yeah, that's what I was trying to explain. Only the first radio button can be targeted by tabbing: http://jsbin.com/cubiy/1 Anything else that didn't work for you?

Jacob
Owner
fat commented

@hnrch02 in your demo: http://jsbin.com/fikul/5/edit

when you tab to the radio, you just use your keyboard left, right, etc.…

Jacob
Owner
fat commented

i believe that is expected for radio inputs, accessibility, etc. but i could be mistaken

Heinrich Fenkart

Oh wow, I see, wasn't aware of that. I guess then it's good to go :smile:

Jacob
Owner
fat commented

@mdo - does it work for you if you use arrows… just want to confirm before mergin

Mark Otto
Owner
mdo commented

Ohhhhhh snap. :thumbsup:

Mark Otto
Owner
mdo commented

@hnrch02 What other styles do we need added?

screen shot 2014-07-06 at 1 06 41 am

Heinrich Fenkart

@mdo Styles for the focus class? It's all about the checkboxes and radios.

Mark Otto
Owner
mdo commented

As far as I can tell they are receiving focus styles.

Mark Otto mdo merged commit 907b3b2 into from
Mark Otto mdo closed this
Mark Otto mdo deleted the branch
Chris Rebert cvrebert referenced this pull request
Open

v3.2.1 ship list #13952

Heinrich Fenkart

@mdo Well, then I must be doing something wrong:
Screenshot

Checkbox 1 has the focus class but no outline.

Mark Otto
Owner
mdo commented

@hnrch02 I see focus styles in Chrome, Firefox, and Safari on OS X. You on Windows?

Heinrich Fenkart

@hnrch02 Nope, Chrome 36.0.1985.103 beta on OS X 10.9.4. Also not seeing them in Firefox 30. Safari.

Mark Otto
Owner
mdo commented

Damn beta software. I wonder if Chrome is changing how it handles focus? I see what I posted in my screenshot without issue.

Heinrich Fenkart

@mdo Just to be clear, you tab to Checkbox 1 and you see a focus outline?

Mark Otto
Owner
mdo commented

screen shot 2014-07-07 at 12 56 20 am

Heinrich Fenkart

@mdo Would you mind opening the CSS tab in that Bin? It includes a modified version of the button-variant mixin with the focus class.

Mark Otto
Owner
mdo commented

Lol.

Heinrich Fenkart hnrch02 referenced this pull request from a commit in hnrch02/bootstrap
Heinrich Fenkart hnrch02 Follow-up to #13907: simplify JS logic for focus shim cc7fab8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 24, 2014
Jacob fat add "focus" to focused btns with button plugin 6b6476f
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 22 additions and 6 deletions. Show diff stats Hide diff stats

  1. +22 6 js/button.js
28 js/button.js
@@ -97,14 +97,30 @@
97 97 }
98 98
99 99
  100 + // FOCUS SHIM (FOR BUTTON GROUPS)
  101 + // ==============================
  102 +
  103 + function getBtnTarget(target) {
  104 + var $target = $(target)
  105 + return $target.hasClass('btn') ? $target : $target.parent('.btn')
  106 + }
  107 +
  108 +
100 109 // BUTTON DATA-API
101 110 // ===============
102 111
103   - $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
104   - var $btn = $(e.target)
105   - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
106   - Plugin.call($btn, 'toggle')
107   - e.preventDefault()
108   - })
  112 + $(document)
  113 + .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
  114 + var $btn = $(e.target)
  115 + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
  116 + Plugin.call($btn, 'toggle')
  117 + e.preventDefault()
  118 + })
  119 + .on('focus.bs.button.data-api', '[data-toggle^="button"]', function (e) {
  120 + getBtnTarget(e.target).addClass('focus')
  121 + })
  122 + .on('blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
  123 + getBtnTarget(e.target).removeClass('focus')
  124 + })
109 125
110 126 }(jQuery);
Image

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.