Skip to content

Commit

Permalink
Set outlineStyle instead of outline when preventing outline
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops committed Apr 12, 2023
1 parent c53de88 commit 4af605a
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
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,23 @@ describe('DomUtil', () => {
describe('#preventOutline, #restoreOutline', () => {
it('prevent / restore outline for the element', () => {
const child = document.createElement('div');
el.appendChild(child);
const 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.equal('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.equal(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.equal('none');
UIEventSimulator.fire('keydown', child);
expect(child.style.outline).to.be.equal(child.style.outline);
expect(child.style.outlineStyle).to.be.equal(originalStyle);
});
});
});
6 changes: 3 additions & 3 deletions src/dom/DomUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,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`](#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 4af605a

Please sign in to comment.