{"action":"created","comment":{"url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/comments/56585570","id":56585570,"diff_hunk":"@@ -496,29 +465,68 @@\n       }\n     },\n \n+    /**\n+     * Cancels (closes) the overlay. Call when click happens outside the overlay.\n+     * @param {!Event} event\n+     * @protected\n+     */\n     _onCaptureClick: function(event) {\n-      if (this._manager.currentOverlay() === this &&\n-          Polymer.dom(event).path.indexOf(this) === -1) {\n-        if (this.noCancelOnOutsideClick) {\n-          this._applyFocus();\n-        } else {\n-          this.cancel(event);\n-        }\n+      if (!this.noCancelOnOutsideClick) {\n+        this.cancel(event);\n       }\n     },\n \n+    /**\n+     * Keeps track of the focused child. If withBackdrop, traps focus within overlay.\n+     * @param {!Event} event\n+     * @protected\n+     */\n     _onCaptureFocus: function (event) {\n-      if (this._manager.currentOverlay() === this && this.withBackdrop) {\n-        var path = Polymer.dom(event).path;\n-        if (path.indexOf(this) === -1) {\n-          event.stopPropagation();\n-          this._applyFocus();\n-        } else {\n-          this._focusedChild = path[0];\n-        }\n+      if (!this.withBackdrop) {\n+        return;\n+      }\n+      var path = Polymer.dom(event).path;\n+      if (path.indexOf(this) === -1) {\n+        event.stopPropagation();\n+        this._applyFocus();\n+      } else {\n+        this._focusedChild = path[0];\n+      }\n+    },\n+\n+    /**\n+     * Cancels (closes) the overlay.\n+     * @param {!Event} event\n+     * @protected\n+     */\n+    _onCaptureEsc: function(event) {\n+      if (!this.noCancelOnEscKey) {\n+        this.cancel(event);\n       }\n     },\n \n+    /**\n+     * Will wrap focus for overlays withBackdrop.\n+     * @param {!Event} event\n+     * @protected\n+     */\n+    _onCaptureTab: function(event) {\n+      // TAB wraps from last to first focusable.\n+      // Shift + TAB wraps from first to last focusable.\n+      var shift = event.shiftKey;\n+      var nodeToCheck = shift ? this.__firstFocusableNode : this.__lastFocusableNode;\n+      var nodeToSet = shift ? this.__lastFocusableNode : this.__firstFocusableNode;","path":"iron-overlay-behavior.html","position":262,"original_position":262,"commit_id":"9cbd3e3c700551c40198be1c18923269e4bb1a31","original_commit_id":"9cbd3e3c700551c40198be1c18923269e4bb1a31","user":{"login":"cdata","id":240083,"avatar_url":"https://avatars.githubusercontent.com/u/240083?v=3","gravatar_id":"","url":"https://api.github.com/users/cdata","html_url":"https://github.com/cdata","followers_url":"https://api.github.com/users/cdata/followers","following_url":"https://api.github.com/users/cdata/following{/other_user}","gists_url":"https://api.github.com/users/cdata/gists{/gist_id}","starred_url":"https://api.github.com/users/cdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdata/subscriptions","organizations_url":"https://api.github.com/users/cdata/orgs","repos_url":"https://api.github.com/users/cdata/repos","events_url":"https://api.github.com/users/cdata/events{/privacy}","received_events_url":"https://api.github.com/users/cdata/received_events","type":"User","site_admin":false},"body":"_No action required_, but thinking out loud: it would be nice if we could generalize \"constraining focus to a subtree\" as a behavior or something. It's useful outside of the overlay case (like in drawer panel).","created_at":"2016-03-17T22:05:42Z","updated_at":"2016-03-17T22:05:42Z","html_url":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116#discussion_r56585570","pull_request_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/comments/56585570"},"html":{"href":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116#discussion_r56585570"},"pull_request":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116","id":60597807,"html_url":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116","diff_url":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116.diff","patch_url":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116.patch","issue_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/116","number":116,"state":"open","locked":false,"title":"Click, focus, keydown listeners on manager","user":{"login":"valdrinkoshi","id":6173664,"avatar_url":"https://avatars.githubusercontent.com/u/6173664?v=3","gravatar_id":"","url":"https://api.github.com/users/valdrinkoshi","html_url":"https://github.com/valdrinkoshi","followers_url":"https://api.github.com/users/valdrinkoshi/followers","following_url":"https://api.github.com/users/valdrinkoshi/following{/other_user}","gists_url":"https://api.github.com/users/valdrinkoshi/gists{/gist_id}","starred_url":"https://api.github.com/users/valdrinkoshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valdrinkoshi/subscriptions","organizations_url":"https://api.github.com/users/valdrinkoshi/orgs","repos_url":"https://api.github.com/users/valdrinkoshi/repos","events_url":"https://api.github.com/users/valdrinkoshi/events{/privacy}","received_events_url":"https://api.github.com/users/valdrinkoshi/received_events","type":"User","site_admin":false},"body":"Fixes #109, fixes #117 by handling click and focus listeners on `iron-overlay-manager`.\r\n\r\nPreviously, each overlay would have these listeners, and these were toggled a tick after `_onOpenedChanged` (to avoid the triggering click event to close them). This was cumbersome because we'd have a lot of listeners, and each overlay would check if it is the `currentOverlay`.\r\n\r\nNow, `iron-overlay-manager` will always listen for `click` and `focus`, and delegates the actions only to the current/top overlay (does also some other safety checks). To avoid the immediate closing, we delay the setting of `currentOverlay` for a tick. This fixes also #117.\r\n\r\nFinally, we synchronously update the `_overlays`, so that we are sure the array will always contain opened overlays. This allowed to remove `_backdrops`.\r\n\r\n`keydown` listener moved to the Manager as well, in order to use `useCapture` and have less listeners.\r\n\r\n\r\nSome examples:\r\n- [2 nested overlays](http://jsbin.com/xuguxa/1/edit?html,output) - [with the fix](http://jsbin.com/savivac/1/edit?html,output)\r\n- [2 overlays](http://jsbin.com/zipugig/2/edit?html,output) - [with the fix](http://jsbin.com/vebinu/12/edit?html,output)\r\n- [2 dropdowns](http://jsbin.com/reqayid/3/edit?html,output) - [with the fix](http://jsbin.com/dafaho/3/edit?html,output)","created_at":"2016-02-24T23:26:08Z","updated_at":"2016-03-17T22:05:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"874aa81c91b5f9c710ea0003d291e7dae67e5db0","assignee":{"login":"cdata","id":240083,"avatar_url":"https://avatars.githubusercontent.com/u/240083?v=3","gravatar_id":"","url":"https://api.github.com/users/cdata","html_url":"https://github.com/cdata","followers_url":"https://api.github.com/users/cdata/followers","following_url":"https://api.github.com/users/cdata/following{/other_user}","gists_url":"https://api.github.com/users/cdata/gists{/gist_id}","starred_url":"https://api.github.com/users/cdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdata/subscriptions","organizations_url":"https://api.github.com/users/cdata/orgs","repos_url":"https://api.github.com/users/cdata/repos","events_url":"https://api.github.com/users/cdata/events{/privacy}","received_events_url":"https://api.github.com/users/cdata/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116/commits","review_comments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116/comments","review_comment_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/116/comments","statuses_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/statuses/9cbd3e3c700551c40198be1c18923269e4bb1a31","head":{"label":"PolymerElements:issue-109","ref":"issue-109","sha":"9cbd3e3c700551c40198be1c18923269e4bb1a31","user":{"login":"PolymerElements","id":11639138,"avatar_url":"https://avatars.githubusercontent.com/u/11639138?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerElements","html_url":"https://github.com/PolymerElements","followers_url":"https://api.github.com/users/PolymerElements/followers","following_url":"https://api.github.com/users/PolymerElements/following{/other_user}","gists_url":"https://api.github.com/users/PolymerElements/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerElements/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerElements/subscriptions","organizations_url":"https://api.github.com/users/PolymerElements/orgs","repos_url":"https://api.github.com/users/PolymerElements/repos","events_url":"https://api.github.com/users/PolymerElements/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerElements/received_events","type":"Organization","site_admin":false},"repo":{"id":34762920,"name":"iron-overlay-behavior","full_name":"PolymerElements/iron-overlay-behavior","owner":{"login":"PolymerElements","id":11639138,"avatar_url":"https://avatars.githubusercontent.com/u/11639138?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerElements","html_url":"https://github.com/PolymerElements","followers_url":"https://api.github.com/users/PolymerElements/followers","following_url":"https://api.github.com/users/PolymerElements/following{/other_user}","gists_url":"https://api.github.com/users/PolymerElements/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerElements/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerElements/subscriptions","organizations_url":"https://api.github.com/users/PolymerElements/orgs","repos_url":"https://api.github.com/users/PolymerElements/repos","events_url":"https://api.github.com/users/PolymerElements/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerElements/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PolymerElements/iron-overlay-behavior","description":"Makes an element an overlay with an optional backdrop","fork":false,"url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior","forks_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/forks","keys_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/teams","hooks_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/hooks","issue_events_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/events{/number}","events_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/events","assignees_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/assignees{/user}","branches_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/branches{/branch}","tags_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/tags","blobs_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/refs{/sha}","trees_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/statuses/{sha}","languages_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/languages","stargazers_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/stargazers","contributors_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/contributors","subscribers_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/subscribers","subscription_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/subscription","commits_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/commits{/sha}","git_commits_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/commits{/sha}","comments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/comments{/number}","issue_comment_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/comments{/number}","contents_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/contents/{+path}","compare_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/merges","archive_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/downloads","issues_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues{/number}","pulls_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls{/number}","milestones_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/milestones{/number}","notifications_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/labels{/name}","releases_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/releases{/id}","deployments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/deployments","created_at":"2015-04-29T00:18:57Z","updated_at":"2016-03-11T13:09:47Z","pushed_at":"2016-03-17T18:12:00Z","git_url":"git://github.com/PolymerElements/iron-overlay-behavior.git","ssh_url":"git@github.com:PolymerElements/iron-overlay-behavior.git","clone_url":"https://github.com/PolymerElements/iron-overlay-behavior.git","svn_url":"https://github.com/PolymerElements/iron-overlay-behavior","homepage":null,"size":208,"stargazers_count":3,"watchers_count":3,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":13,"forks":20,"open_issues":13,"watchers":3,"default_branch":"master"}},"base":{"label":"PolymerElements:master","ref":"master","sha":"6b8662619fbd4e82c2cebce6a846425ff9fc610d","user":{"login":"PolymerElements","id":11639138,"avatar_url":"https://avatars.githubusercontent.com/u/11639138?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerElements","html_url":"https://github.com/PolymerElements","followers_url":"https://api.github.com/users/PolymerElements/followers","following_url":"https://api.github.com/users/PolymerElements/following{/other_user}","gists_url":"https://api.github.com/users/PolymerElements/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerElements/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerElements/subscriptions","organizations_url":"https://api.github.com/users/PolymerElements/orgs","repos_url":"https://api.github.com/users/PolymerElements/repos","events_url":"https://api.github.com/users/PolymerElements/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerElements/received_events","type":"Organization","site_admin":false},"repo":{"id":34762920,"name":"iron-overlay-behavior","full_name":"PolymerElements/iron-overlay-behavior","owner":{"login":"PolymerElements","id":11639138,"avatar_url":"https://avatars.githubusercontent.com/u/11639138?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerElements","html_url":"https://github.com/PolymerElements","followers_url":"https://api.github.com/users/PolymerElements/followers","following_url":"https://api.github.com/users/PolymerElements/following{/other_user}","gists_url":"https://api.github.com/users/PolymerElements/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerElements/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerElements/subscriptions","organizations_url":"https://api.github.com/users/PolymerElements/orgs","repos_url":"https://api.github.com/users/PolymerElements/repos","events_url":"https://api.github.com/users/PolymerElements/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerElements/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PolymerElements/iron-overlay-behavior","description":"Makes an element an overlay with an optional backdrop","fork":false,"url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior","forks_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/forks","keys_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/teams","hooks_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/hooks","issue_events_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/events{/number}","events_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/events","assignees_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/assignees{/user}","branches_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/branches{/branch}","tags_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/tags","blobs_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/refs{/sha}","trees_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/statuses/{sha}","languages_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/languages","stargazers_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/stargazers","contributors_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/contributors","subscribers_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/subscribers","subscription_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/subscription","commits_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/commits{/sha}","git_commits_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/git/commits{/sha}","comments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/comments{/number}","issue_comment_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/comments{/number}","contents_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/contents/{+path}","compare_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/merges","archive_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/downloads","issues_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues{/number}","pulls_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls{/number}","milestones_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/milestones{/number}","notifications_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/labels{/name}","releases_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/releases{/id}","deployments_url":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/deployments","created_at":"2015-04-29T00:18:57Z","updated_at":"2016-03-11T13:09:47Z","pushed_at":"2016-03-17T18:12:00Z","git_url":"git://github.com/PolymerElements/iron-overlay-behavior.git","ssh_url":"git@github.com:PolymerElements/iron-overlay-behavior.git","clone_url":"https://github.com/PolymerElements/iron-overlay-behavior.git","svn_url":"https://github.com/PolymerElements/iron-overlay-behavior","homepage":null,"size":208,"stargazers_count":3,"watchers_count":3,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":13,"forks":20,"open_issues":13,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116"},"html":{"href":"https://github.com/PolymerElements/iron-overlay-behavior/pull/116"},"issue":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/116"},"comments":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/PolymerElements/iron-overlay-behavior/statuses/9cbd3e3c700551c40198be1c18923269e4bb1a31"}}}}