Skip to content

Conversation

dubchenko
Copy link

@dubchenko dubchenko commented Jun 17, 2019

Describe the PR

Browser alert and confirm modal windows are submitted on Enter. Bootstrap-vue doesn't support such behaviour. This PR fixes this.

PR checklist

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Enhancement
  • ARIA accessibility
  • Documentation update
  • Other (please describe)

Does this PR introduce a breaking change? (check one)

  • No
  • Yes (please describe) pressing enter inside a modal will close it with OK status by default.

The PR fulfills these requirements:

  • It's submitted to the dev branch, not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (i.e. [...] (fixes #xxx[,#xxx]), where "xxx" is the issue number)
  • It should address only one issue or feature. If adding multiple features or fixing a bug and adding a new feature, break them into separate PRs if at all possible.
  • The title should follow the Conventional Commits naming convention (i.e. fix(alert): not alerting during SSR render, docs(badge): update pill examples, fix typos, chore: fix typo in README, etc). This is very important, as the CHANGELOG is generated from these messages.

If new features/enhancement/fixes are added or changed:

  • Includes documentation updates (including updating the component's package.json for slot and event changes)
  • New/updated tests are included and passing (if required)
  • Existing test suites are passing
  • The changes have not impacted the functionality of other components or directives
  • ARIA Accessibility has been taken into consideration (Does it affect screen reader users or keyboard only users? Clickable items should be in the tab index, etc.)

If adding a new feature, or changing the functionality of an existing feature, the PR's
description above includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

// If Enter pressed, submit modal
if (evt.keyCode === KeyCodes.ENTER && this.isVisible && !this.noSubmitOnEnter) {
this.onOk()
}
Copy link
Member

@tmorehouse tmorehouse Jun 17, 2019

Choose a reason for hiding this comment

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

This would close the modal even in there are cancel buttons, etc. It assumes the user wants the default action to be OK (and not Cancel)

Copy link
Author

Choose a reason for hiding this comment

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

Would it ok to pass the default action via props?

Copy link
Member

Choose a reason for hiding this comment

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

It would probably be better to have some option(s) to specify which default rendered buttons have focus when the modal opens (defaulting to no buttons having focus, as autofocusing an input or button on a modal will usually only announce the button/input but not the modal content when using screen readers.

A more robust approach is to have users listen for the shown event, and then focus the element they want (be it a button, input, or other focusable content control).

The shown event includes a reference to the modal element in the bvEvent object (the target property). Once shown, you can then use bvEvent.target.querySelector('some selector criteria)` to find an element and focus it.

@codecov
Copy link

codecov bot commented Jun 17, 2019

Codecov Report

Merging #3542 into dev will decrease coverage by 0.02%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #3542      +/-   ##
==========================================
- Coverage   99.25%   99.23%   -0.03%     
==========================================
  Files         224      224              
  Lines        4315     4317       +2     
  Branches     1231     1232       +1     
==========================================
+ Hits         4283     4284       +1     
- Misses         26       27       +1     
  Partials        6        6
Impacted Files Coverage Δ
src/components/modal/modal.js 99.08% <50%> (-0.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 337b2bd...e05c231. Read the comment docs.

@tmorehouse
Copy link
Member

tmorehouse commented Jun 17, 2019

It probably would be better to handle this in the app logic rather than inside the modal component.

i.e. listening for enter keypress on an input, or replacing the default buttons with a button with a that you have access to the $ref of which you can auto-focus once modal is shown (which will trigger it to click when pressing enter)

This PR assumes that OK is the default, when users may want the default action to be Cancel

noSubmitOnEnter: {
type: Boolean,
default: false
},
Copy link
Member

Choose a reason for hiding this comment

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

This also assumes people want to close modal on ENTER, which is currently not the default behavior and would be considered a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Also, submit assumes a form is being used... so its probably not the best name for the prop, as modals don't "submit"

@dubchenko
Copy link
Author

msgBoxConfirm and msgBoxOk doesn’t provide access to buttons via $ref

@tmorehouse
Copy link
Member

If you pass an ID to the msgBox methods, you can then listen for shown events on $root, and match the ID passed, and then use the bvEvent.target to focus a prop.

@tmorehouse
Copy link
Member

If you had a msgBox with an OK and CANCEL button, and the user had CANCEL focused (i.e. they tabbed to CANCEL), your enter handler would trigger the OK action, not the cancel action (which is what the user would be expecting)

@tmorehouse
Copy link
Member

tmorehouse commented Jun 17, 2019

What would be better is a prop called autofocus-button which accepts a string of either ok or cancel, (or null or empty string, for default of no autofocus) which modal could then use it's own internal $refs to focus the appropriate button (if the $ref exists and is visible).

It would need tests for coverage, and documentation on the prop, with a note that it only works with the default built in footer buttons. and a note that auto-focusing a control inside the modal may prevent the modal content from being read out for screen reader users.

@dubchenko
Copy link
Author

@tmorehouse thank you!

@dragospeta
Copy link

When will we have this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants