Skip to content

Commit

Permalink
Set outlineStyle instead of outline when preventing outline (#8917)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops authored and Falke-Design committed May 18, 2023
1 parent 830b424 commit 8602948
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions spec/suites/dom/DomUtilSpec.js
Expand Up @@ -415,22 +415,23 @@ describe('DomUtil', function () {
describe('#preventOutline, #restoreOutline', function () {
(L.Browser.ie ? it.skip : it)('prevent / restore outline for the element', function () {
var child = document.createElement('div');
el.appendChild(child);
var originalStyle = child.style.outlineStyle = 'dotted';

child.tabIndex = 0;
expect(child.style.outline).to.be.equal(child.style.outline);
el.appendChild(child);

L.DomUtil.preventOutline(child);
expect(child.style.outline).to.match(/(?:none)/);
expect(child.style.outlineStyle).to.eql('none');

// Explicit #restoreOutline through direct call
expect(child.style.outline).to.match(/(?:none)/);
// Explicit #restoreOutline through direct call
L.DomUtil.restoreOutline(child);
expect(child.style.outline).to.be.equal(child.style.outline);
expect(child.style.outlineStyle).to.be.eql(originalStyle);

// Implicit #restoreOutline test through simulation
// Implicit #restoreOutline test through simulation
L.DomUtil.preventOutline(child);
expect(child.style.outline).to.match(/(?:none)/);
expect(child.style.outlineStyle).to.eql('none');
happen.once(child, {type: 'keydown'});
expect(child.style.outline).to.be.equal(child.style.outline);
expect(child.style.outlineStyle).to.be.eql(originalStyle);
});
});
});
6 changes: 3 additions & 3 deletions src/dom/DomUtil.js
Expand Up @@ -310,16 +310,16 @@ export function preventOutline(element) {
if (!element.style) { return; }
restoreOutline();
_outlineElement = element;
_outlineStyle = element.style.outline;
element.style.outline = 'none';
_outlineStyle = element.style.outlineStyle;
element.style.outlineStyle = 'none';
DomEvent.on(window, 'keydown', restoreOutline);
}

// @function restoreOutline()
// Cancels the effects of a previous [`L.DomUtil.preventOutline`]().
export function restoreOutline() {
if (!_outlineElement) { return; }
_outlineElement.style.outline = _outlineStyle;
_outlineElement.style.outlineStyle = _outlineStyle;
_outlineElement = undefined;
_outlineStyle = undefined;
DomEvent.off(window, 'keydown', restoreOutline);
Expand Down

0 comments on commit 8602948

Please sign in to comment.