Skip to content

fix(item-sliding): close open item when pressing outside of it - #31841

Open
toyeshhm wants to merge 1 commit into
ionic-team:mainfrom
toyeshhm:fix-29504-close-on-outside-click
Open

toyeshhm wants to merge 1 commit into
ionic-team:mainfrom
toyeshhm:fix-29504-close-on-outside-click

Conversation

@toyeshhm

Copy link
Copy Markdown

Issue number: resolves #29504


What is the current behavior?

Once an ion-item-sliding is opened, by swiping or by calling open(), it stays open until the user swipes it closed, swipes a different sliding item, or the app calls close() / closeSlidingItems(). Tapping anywhere else on the page leaves it open. On native iOS and Android, an open item closes as soon as the user presses anywhere outside of it.

The only automatic close today is in canStart, which closes the previously open item when another sliding item starts a gesture.

What is the new behavior?

  • While an item is open, it listens for pointerdown on the document and closes when the press lands outside of the item. Presses on the item's own options do not close it, so option buttons still work.
  • The listener is added in the two places that set the open item (onStart and open()) and removed when the item closes or is disconnected, so nothing listens while every item is closed.
  • The listener uses the capture phase so an application's own pointerdown handler that stops propagation can't keep the item open, and it checks composedPath() so an item inside another component's Shadow DOM is still detected correctly. Both follow what ion-picker-column already does for its outside press.
  • Added e2e tests in item-sliding/test/basic: pressing outside closes an item opened with open(), pressing outside closes a swiped open item, and pressing one of the item's options leaves it open. The two "pressing outside" tests fail on main in all three browsers and pass with this change.

Does this introduce a breaking change?

  • Yes
  • No

Other information

The press that closes the item is not swallowed. If the user taps another item while one is open, that item's click still fires after the open one closes. Native lists also swallow that tap; I left it out to keep this change to closing the item and not change how clicks reach other elements.

Ran locally: the item-sliding, list, item-option and item-options e2e suites (Mobile Chrome, Mobile Firefox, Mobile Safari), plus eslint and prettier on the changed files. I couldn't run the Docker screenshot setup, so screenshot tests ran against the local renderer. One of them, the Safari safe-area screenshot, failed once on a 382-pixel diff and then passed 12 out of 12 reruns. That test drags an item and takes a screenshot without pressing outside, so this change doesn't touch it.

Native lists close an open sliding item when the user presses anywhere else. While an item is open, listen for pointerdown on the document and close it when the press lands outside the item.
@toyeshhm
toyeshhm requested a review from a team as a code owner November 26, 2026 22:52
@toyeshhm
toyeshhm requested review from thetaPC and a balanced review from Copilot November 26, 2026 22:52
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

@toyeshhm is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added the package: core @ionic/core package label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-item-sliding should close automatically when clicking anywhere in the content

2 participants