Skip to content

Various fixes for Modals #326

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

Merged
merged 17 commits into from
May 2, 2017
Merged

Various fixes for Modals #326

merged 17 commits into from
May 2, 2017

Conversation

tmorehouse
Copy link
Member

@tmorehouse tmorehouse commented May 2, 2017

Various fixes & tweaks:

  • Fixes onEsc issue where hitting ESC and the modal wasn't clicked initially (focused), the modal wouldn't close (see discussion at Added closeOnEsc, hideHeaderClose & enforceFocus #247), by ensuring that an element within the modal (or the modal itself) is focused when modal opens (using $nextTick)
  • Refactored the enforceFocus handler, and only instantiate it when the modal is open (removes it when closed),
  • Added in option to restore focus (returnFocus) to the original element that triggered the modal opening. Works with the v-b-modal directive automatically (i.e. the element with the v-b-modal directive), or can be specified as a prop return-focus. Can be a CSS selector string (i.e. '#mybutton'or an HTMLElement reference).
  • Added in generate-id mixin, in case the modal doesn't have an ID, for aria-labeledby and aria-describedby cross referencing.

For the initial focus on modal open, the modal content is searched for the first focusable element, and if not found defaults to the modal itself. When searching for focusable elements, the following order is used:

  • Footer
  • Body
  • Header
  • Modal itself.

* Create form-input-static.vue

New form-static input

* Added form-input-static compoinent

* Refactored static input

Refactored to use the new `<b-form-input-static>` component

* Switch to bFormInputStatic

Updated child component var to bFormInputStatic to follow proper naming conventions

* Removed lazyFormatter from static-input

* Added trailing semi-colon

To make CircleCI happy

* Added missing 'this'

* [nav-item] add dropdown class

* Added <slot> for robustness

* new b-form-input-static component (#292)

* Create form-input-static.vue

New form-static input

* Added form-input-static compoinent

* Refactored static input

Refactored to use the new `<b-form-input-static>` component

* Switch to bFormInputStatic

Updated child component var to bFormInputStatic to follow proper naming conventions

* Removed lazyFormatter from static-input

* Added trailing semi-colon

To make CircleCI happy

* Added missing 'this'

* Added <slot> for robustness

* fixed missing `.vue` extension on import

* Added missing extension on component import (#293)

* Optimized import order in form-input.vue (#294)

* Added missing extension on component import

* Optimized import order
Ensures that the first focusable item in the modal is focused when it is shown.
When selecting the item to focus:
- First looks in footer
- Then body
- Then header
- Else focus the modal itself

Also included generate-id mixin for ARIA labeling
Changed from listing for focus to focusin for enforceFocus hanlder
enforceFocus event listeners are now only instantiated when the modal is shown.
Added a second optional argument to the `show::modal` event to allow specifying the element (i.e. button, link) to return focus to when Modal closes.
Allow to return focus to triggering element when modal is closed.
added in prop `returnFocus` to specify element to re-focus to when modal closes.

Accepts either a CSS selector string (i.e. '#mybutton') or an `HTMLElement` reference. If CSS selector string matches more than one element, then only the first element is re-focused.
@tmorehouse tmorehouse requested a review from pi0 May 2, 2017 21:11
export default {
mixins: [generateId],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateId usage should be limited to inputs only as is mentioned inside Mixin. Also as of vue 2.3.x we can not trust _uid because they are inconsistent between client server in SSR mode. See here

_uid is internal and should not be used as part of the application state

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. I'll remove that, and make sure aria-labeledby and aria-describedby don't get set if the ID is missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tmorehouse that's so sad that we currently can't have such behavior. I'll make an on/off switch for generateIds so non-ssr users can use them optionally until we can find better way generating consistent IDs :)

tmorehouse added 2 commits May 2, 2017 18:45
`aria-labelledby` and `aria-describedby` will not be present (by setting bound attribute to null) if an `id` is not specified for the modal.
@pi0 pi0 merged commit 0c5b9c6 into bootstrap-vue:master May 2, 2017
@tmorehouse
Copy link
Member Author

Take a new look over, I think I have removed all generate-id references (including this._id)

@tmorehouse tmorehouse deleted the tmorehouse-modal branch May 8, 2017 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants