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

fix: Disabled elements being clickable #28807

Merged
merged 24 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0bb361b
fixes #28788 -- mouse.ts logic
TheoAnastasiadis Jan 26, 2024
622d4f3
fixes #28788 -- e2e test
TheoAnastasiadis Jan 26, 2024
6c8943b
fixes #28788 -- mouse.ts logic
TheoAnastasiadis Jan 26, 2024
2960982
refactoring: minor name changes for readability
TheoAnastasiadis Jan 26, 2024
5028f1d
fixes #24322 --added changelog entry
TheoAnastasiadis Jan 26, 2024
fe7686f
Update packages/driver/src/cy/mouse.ts
TheoAnastasiadis Feb 2, 2024
62a5ddd
Update packages/driver/cypress/e2e/commands/actions/click.cy.js
TheoAnastasiadis Feb 2, 2024
ffa64c6
Update packages/driver/src/cy/mouse.ts
TheoAnastasiadis Feb 2, 2024
4d31116
Update packages/driver/src/cy/mouse.ts
TheoAnastasiadis Feb 2, 2024
f53ed61
update mouse.ts -- unexpected token
TheoAnastasiadis Feb 2, 2024
0fb26a5
docs: moved entry to 13.6.5
TheoAnastasiadis Feb 2, 2024
3cf95ac
Merge branch 'develop' into disabled-click
TheoAnastasiadis Feb 2, 2024
a1d117f
Update CHANGELOG.md
TheoAnastasiadis Feb 2, 2024
a3c2bae
Update CHANGELOG.md
TheoAnastasiadis Feb 2, 2024
fa600b3
Merge branch 'develop' into disabled-click
jennifer-shehane Feb 12, 2024
fb0f330
Update packages/driver/cypress/e2e/commands/actions/click.cy.js
TheoAnastasiadis Feb 15, 2024
a4163e8
Update cli/CHANGELOG.md
TheoAnastasiadis Feb 15, 2024
1dbd5e1
Merge branch 'develop' into disabled-click
TheoAnastasiadis Feb 15, 2024
3ffbf02
lint: fixed 2 linting errors
TheoAnastasiadis Feb 16, 2024
dbfd2c0
style: removed trailing space
TheoAnastasiadis Feb 16, 2024
ab36b53
Merge branch 'develop' into disabled-click
jennifer-shehane Feb 21, 2024
cf63b00
Merge branch 'develop' into disabled-click
TheoAnastasiadis Feb 23, 2024
c4c2eb6
Merge branch 'develop' into disabled-click
TheoAnastasiadis Feb 24, 2024
1a0697b
Update CHANGELOG.md
cacieprins Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _Released 2/27/2024 (PENDING)_

**Bugfixes:**

- Fixed an issue where `.click()` commands on children of disabled elements would still produce "click" events -- even without `{ force: true }`. Fixes [#28788](https://github.com/cypress-io/cypress/issues/28788).
- Changed RequestBody type to allow for boolean and null literals to be passed as body values. [#28789](https://github.com/cypress-io/cypress/issues/28789)

## 13.6.6
Expand All @@ -21,6 +22,7 @@ _Released 2/20/2024_

**Bugfixes:**

- Fixed an issue where `.click()` commands on children of disabled elements would still produce "click" events -- even without `{ force: true }`. Fixes [#28788](https://github.com/cypress-io/cypress/issues/28788).
- Fixed tests hanging when the Chrome browser extension is disabled. Fixes [#28392](https://github.com/cypress-io/cypress/issues/28392).
- Fixed an issue which caused the browser to relaunch after closing the browser from the Launchpad. Fixes [#28852](https://github.com/cypress-io/cypress/issues/28852).
- Fixed an issue with the unzip promise never being rejected when an empty error happens. Fixed in [#28850](https://github.com/cypress-io/cypress/pull/28850).
Expand Down
24 changes: 24 additions & 0 deletions packages/driver/cypress/e2e/commands/actions/click.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,30 @@ describe('src/cy/commands/actions/click', () => {
cy.getAll('span2', 'focus click mousedown').each(shouldNotBeCalled)
})

// https://github.com/cypress-io/cypress/issues/28788
it('no click when element is disabled', () => {
const btn = cy.$$('button:first')
const span = $('<span>foooo</span>')

attachFocusListeners({ btn, span })
attachMouseClickListeners({ btn, span })
attachMouseHoverListeners({ btn, span })

btn.html('')
btn.attr('disabled', true)
btn.append(span)

cy.get('button:first span').click()

if (Cypress.browser.name === 'chrome') {
cy.getAll('btn', 'mouseenter mousedown mouseup').each(shouldBeCalled)
}

cy.getAll('btn', 'focus click').each(shouldNotBeCalled)
cy.getAll('span', 'mouseenter mousedown mouseup').each(shouldBeCalled)
cy.getAll('span', 'focus click').each(shouldNotBeCalled)
})

it('no click when new element at coords is not ancestor', () => {
const btn = cy.$$('button:first')
const span1 = $('<span>foooo</span>')
Expand Down
15 changes: 15 additions & 0 deletions packages/driver/src/cy/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,21 @@ export const create = (state: StateFunc, keyboard: Keyboard, focused: IFocused,
return { skipClickEventReason: 'element was detached' }
}

// Only send click event if element is not disabled.
// First find an parent element that can actually be disabled
const findParentThatCanBeDisabled = (el: HTMLElement): HTMLElement | null => {
const elementsThatCanBeDisabled = ['button', 'input', 'select', 'textarea', 'optgroup', 'option', 'fieldset']

return elementsThatCanBeDisabled.includes($elements.getTagName(el)) ? el : null
}

const parentThatCanBeDisabled = $elements.findParent(mouseUpPhase.targetEl, findParentThatCanBeDisabled) || $elements.findParent(mouseDownPhase.targetEl, findParentThatCanBeDisabled)

// Then check if parent is indeed disabled
if (parentThatCanBeDisabled !== null && $elements.isDisabled($(parentThatCanBeDisabled))) {
return { skipClickEventReason: 'element was disabled' }
}

const commonAncestor = mouseUpPhase.targetEl &&
mouseDownPhase.targetEl &&
$elements.getFirstCommonAncestor(mouseUpPhase.targetEl, mouseDownPhase.targetEl)
Expand Down