Commit b2247398 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'preventdefault-disabled-buttons' into 'master'

Prevent default disabled buttons and links.

## What does this MR do?
Prevents default action for disabled buttons and links. If the element has `.btn` and `.disabled` at the same time, its default action will be prevented.

## Are there points in the code the reviewer needs to double check?
Yes. Is there a better way to do that?

## Why was this MR needed?
Right now we can click disabled links and it cause some troubles like in #18079.

## What are the relevant issue numbers?
Fixes #18079

## Screenshots (if relevant)
![disabled-click](/uploads/48b58ce130f843e530e62632bcc27436/disabled-click.gif)

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- [x] Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !4658
parents a69cd321 415b032b
......@@ -77,6 +77,7 @@ v 8.9.0 (unreleased)
- RepositoryCheck::SingleRepositoryWorker public and private methods are now instrumented
- Improve issuables APIs performance when accessing notes !4471
- External links now open in a new tab
- Prevent default actions of disabled buttons and links
- Markdown editor now correctly resets the input value on edit cancellation !4175
- Toggling a task list item in a issue/mr description does not creates a Todo for mentions
- Improved UX of date pickers on issue & milestone forms
......
......@@ -125,6 +125,7 @@ window.onload = ->
setTimeout shiftWindow, 100
$ ->
gl.utils.preventDisabledButtons()
bootstrapBreakpoint = bp.getBreakpointSize()
$(".nicescroll").niceScroll(cursoropacitymax: '0.4', cursorcolor: '#FFF', cursorborder: "1px solid #FFF")
......
......@@ -32,5 +32,12 @@
.attr 'title', newTitle
.tooltip 'fixTitle'
gl.utils.preventDisabledButtons = ->
$('.btn').click (e) ->
if $(this).hasClass 'disabled'
e.preventDefault()
e.stopImmediatePropagation()
return false
) window
#= require lib/common_utils
describe 'Application', ->
describe 'disable buttons', ->
fixture.preload('application.html')
beforeEach ->
fixture.load('application.html')
it 'should prevent default action for disabled buttons', ->
gl.utils.preventDisabledButtons()
isClicked = false
$button = $ '#test-button'
$button.click -> isClicked = true
$button.trigger 'click'
expect(isClicked).toBe false
it 'should be on the same page if a disabled link clicked', ->
locationBeforeLinkClick = window.location.href
gl.utils.preventDisabledButtons()
$('#test-link').click()
expect(window.location.href).toBe locationBeforeLinkClick
%a#test-link.btn.disabled{:href => "/foo"} Test link
%button#test-button.btn.disabled Test Button
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment