mdPanel: Always traps focus. Setting trapFocus to false doesn't work
Actual Behavior:
What is the issue?Focus is is always trapped when the panel appears and there is no way to allow the user to interact with the rest of the application while the panel is displayed.What is the expected behavior?Would expect setting trapFocus to false would allow the user to interact with the rest of the application while the panel is open.
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:http://codepen.io/anon/pen/bZWNBQDetails:Have modified the demo codepen to demonstrate this issue. The trapFocus parameter is set to false but focus is still trapped. Just click the dialog button and attempt to interact with the checkbox in the background.
Angular Versions: *
Angular Version:AngularJS v1.5.7Angular Material Version:Angular Material Version: v1.1.0-rc.5-master-8758488
Additional Information:
Browser Type: *Chrome, IEBrowser Version: *chrome latest, IE11OS: *Windows 7Stack Traces:
Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.
Do not modify the titles or questions. Simply add your responses to the ends of the questions. Add more lines if needed.
@vaughnmuirhead I had a bit of a similar issue when I was using mdPanel recently. I believe the reason trapFocus isn't working as you anticipate is because of the attachTo in the panel config. The panel makes a wrapper element that covers the element you've attached the panel to; in this case, the document body. The trapFocus parameter works as anticipated if you attach it to another element. Here's a demo where I've attach it to the checkbox, and it doesn't trap focus for the element it's attached to (keep in mind though, that since it's been attached to the checkbox, it's been inserted into the md-checkbox and clicking on the dialog activates the checkbox, which gets us nowhere). I'm not sure why it doesn't operate the same way with the document body, but I have a suspicion that it only doesn't trap focus for the element that you've attached it to, not the children elements. Modifying the previous demo to attach it to the div above the checkbox makes the checkbox un-inter-actable again, so we're back at square 1, but with a bit more knowledge as it behaves the same way as attaching it to the document body.
In the meantime, I've worked around this on my application my targeting the wrapper element that prevents interaction via css:
.md-panel-outer-wrapper {
width: 0 !important;
height: 0 !important;
}
Here's your initial demo with that css applied. Things are inter-actable, but it does mess up the trapFocus in that there's not a way to tell the panel there are some panels you do want to trap focus for. There's not a pure-css way to change a parent element's classes based on what children it has, so for now if we want a trapFocus aware panel, we need to use the panel's callbacks.
Here is a bit of a jury-rigged example that applies a width: 0, height: 0 css class if the panel config has trapFocus set to true. I'd happily welcome any other possible solutions, but for now this works for me.
@zlovin Thanks for the workaround! This fixes my issue perfectly.
@vaughnmuirhead trapFocus is intended to trap the focus within the panel. For instance, if you have a dialog, for accessibility reasons focus cannot leave the dialog until the user dismisses it. So if you continuously hit tab and trapFocus is true, focus cannot leave the panel. If trapFocus is false, focus is directed to the next element in the tab order even if it is outside the panel.
I think the issue you are really asking for is allowing clicks to go through the backdrops. I just filed Issue #8968 for this new option.