The Wayback Machine - https://web.archive.org/web/20201114144509/https://github.com/angular/material/issues/11503
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radio-group: does not scroll into view when changed #11503

Open
NilsAtGoogle opened this issue Nov 2, 2018 · 3 comments
Open

radio-group: does not scroll into view when changed #11503

NilsAtGoogle opened this issue Nov 2, 2018 · 3 comments

Comments

@NilsAtGoogle
Copy link

@NilsAtGoogle NilsAtGoogle commented Nov 2, 2018

Bug

When the user changes a radio group, the radio group should be scrolled into view if it's not currently visible (i.e. mimic the behavior of standard HTML inputs).

CodePen and steps to reproduce the issue:

AngularJS material demo

Detailed Reproduction Steps:

  1. set focus on a radio group
  2. scroll out of view
  3. use keyboard up/down to change selected radio button

What is the expected behavior?

radio group is scrolled into view, so the user is aware their action has changed the input

What is the current behavior?

radio group remains off screen

What is the use-case or motivation for changing an existing behavior?

conformance with HTML input behavior

Which versions of AngularJS, Material, OS, and browsers are affected?

  • AngularJS: any
  • AngularJS Material: 1.1.10
  • OS: any
  • Browsers: Chrome, Firefox (probably all browsers)

Is there anything else we should know? Stack Traces, Screenshots, etc.

@Splaktar Splaktar self-assigned this Nov 3, 2018
@Splaktar Splaktar added this to the 1.1.12 milestone Nov 3, 2018
@Splaktar
Copy link
Member

@Splaktar Splaktar commented Nov 3, 2018

I created a CodePen to demonstrate how this behavior compares to the default HTML radio input.

@Splaktar Splaktar modified the milestones: 1.1.12, 1.1.13 Jan 3, 2019
@Splaktar Splaktar modified the milestones: 1.1.13, 1.1.14 Feb 10, 2019
@Splaktar Splaktar added the g3: sync label Feb 15, 2019
@Splaktar Splaktar modified the milestones: 1.1.14, g3: sync Feb 15, 2019
@kylecjo
Copy link

@kylecjo kylecjo commented Feb 16, 2019

Hi! Is anyone working on this?

@NilsAtGoogle
Copy link
Author

@NilsAtGoogle NilsAtGoogle commented Feb 16, 2019

I've implemented a (somewhat limited) workaround in a local codebase, in case anyone's need is urgent (requires scrollIntoViewIfNeeded and doesn't support model-less radio groups)

This is a postLink function that decorates the original postLink


const scrollFixLink = (scope, element, attrs, [radioGroup, ngModel]) => {
  if (!ngModel) {
    // Do nothing when there is no model
    return;
  }
  const scrollIfNeededOnChange = () => {
    // Experimental: https://caniuse.com/#feat=scrollintoviewifneeded
    if (element[0].scrollIntoViewIfNeeded) {
      element[0].scrollIntoViewIfNeeded(/* opt_center */ false);
    }
  };
  ngModel.$viewChangeListeners.push(scrollIfNeededOnChange);
  scope.$on(
      '$destroy',
      () => remove(ngModel.$viewChangeListeners, scrollIfNeededOnChange));
};

const mdRadioGroupDecorator = ($delegate) => {
  const mdRadioGroup = $delegate[0];
  mdRadioGroup.link.post = scrollFixLink;
  return $delegate;
};
@Splaktar Splaktar added P3: important and removed P4: minor labels Feb 16, 2019
@Splaktar Splaktar modified the milestones: g3: sync, 1.1.23, 1.2.1, 1.2.0 Apr 30, 2020
@Splaktar Splaktar modified the milestones: 1.2.0, 1.2.1 Jul 30, 2020
@Splaktar Splaktar modified the milestones: 1.2.1, 1.2.2 Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.