Skip to content

Commit

Permalink
Toolbar Example: Set focus to button with tabindex="0" when the conta…
Browse files Browse the repository at this point in the history
…iner is clicked (pull #1700)

fixes #987

Co-authored-by: Carolyn MacLeod <[email protected]>
Co-authored-by: Matthew Schad <[email protected]>
Co-authored-by: Matt King <[email protected]>
Co-authored-by: Carolyn MacLeod <[email protected]>
  • Loading branch information
4 people authored Dec 22, 2020
1 parent 1e11b3d commit 13ea4e3
Show file tree
Hide file tree
Showing 4 changed files with 381 additions and 176 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"Thiel",
"Thiers",
"thomascorthals",
"togglable",
"transactinide",
"transuranic",
"Transuranium",
Expand Down
11 changes: 11 additions & 0 deletions examples/toolbar/js/FormatToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ FormatToolbar.prototype.init = function () {
this.domNode.getBoundingClientRect().width - 12 + 'px';
this.textarea.addEventListener('mouseup', this.selectTextContent.bind(this));
this.textarea.addEventListener('keyup', this.selectTextContent.bind(this));
this.domNode.addEventListener('click', this.handleContainerClick.bind(this));

this.selected = this.textarea.selectText;

Expand Down Expand Up @@ -81,6 +82,16 @@ FormatToolbar.prototype.init = function () {
}
};

FormatToolbar.prototype.handleContainerClick = function () {
if (event.target !== this.domNode) return;
this.setFocusCurrentItem();
};

FormatToolbar.prototype.setFocusCurrentItem = function () {
var item = this.domNode.querySelector('[tabindex="0"]');
item.focus();
};

FormatToolbar.prototype.selectTextContent = function () {
this.start = this.textarea.selectionStart;
this.end = this.textarea.selectionEnd;
Expand Down
Loading

0 comments on commit 13ea4e3

Please sign in to comment.