components icon indicating copy to clipboard operation
components copied to clipboard

Support focus outputs on button-toggle, slide-toggle etc.

Open devversion opened this issue 10 years ago • 8 comments

For all custom components with an underlying input we should support a focus / blur event on the component host.

Since the most of those components are wrapped inside of <label> element, the focus / blur events will fire like on each click.

  • http://codepen.io/DevVersion/pen/Vmwmvd?editors=1111

I think in this case the focus | blur events will not make any big sense, because those are kind of fired like the click event.

The problem here is, that the label always redirects focus to the underlying input (and the user always clicks on the label)

devversion avatar Nov 04 '16 00:11 devversion

I appreciate that the slide-toggle has a focus class .md-slide-toggle-focused that I can use to style the component when it is focused. Maybe something similar could work for button-toggle.

bsteffl avatar Jan 26 '17 19:01 bsteffl

Is there a way to focus a <md-button-toggle> by default? I have tried giving it md-button-toggle-checked class but doesn't work.

kilgarenone avatar Feb 08 '17 08:02 kilgarenone

I propose having the behavior consistent with the input text control, that is having the focus and blur events fire, like in this Plunker https://plnkr.co/edit/h2OyULESEcE6IBzdAAIG from #4817

We need to use the conditional Angular ngClass on a parent when a child control was focused or blurred.

BaimosTechnologies avatar May 29 '17 08:05 BaimosTechnologies

I thought more about this and also chatted with @crisbeto briefly about this.

We don't really think that it would make sense to add such an output. The reason for this that we would end-up proxying likely every output, which native DOM elements have.

For example: (click), (mouseover) etc.

I would like to close this issue but waiting for @jelbourn's thoughts still.

devversion avatar Jul 17 '17 16:07 devversion

The focus and blur events are special because they don't bubble. There are others as well, but none especially relevant to our components. However, I don't see what you couldn't accomplish with the combination of a "focus class" and use of focusin and focusout.

jelbourn avatar Jul 17 '17 18:07 jelbourn

Thanks guys, replacing (focus) -> (focusin), (blur) -> (focusout) got the job done.

      <md-input-container floatPlaceholder="always"
                          [ngClass]="{'mat-focused':focusedChannels}">
        <input mdInput id="channels" style="display: none">
        <md-checkbox #checkboxChannel
                     (focusin)="focusedChannels=true" (focusout)="focusedChannels=false">
          Checkbox Label
        </md-checkbox>
      </md-input-container>

BaimosTechnologies avatar Jul 18 '17 09:07 BaimosTechnologies

Going to close that issue, because focusin and focusout seem to be reasonable solutions. It's difficult to re-implement/fire proper focus events with the underlying input, because the <label> element causes the focus to jump between the <label> and <input> element.

devversion avatar Nov 24 '17 19:11 devversion

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.