diff --git a/package-lock.json b/package-lock.json index b9fad5a..6331d8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@advanced-rest-client/arc-response", - "version": "0.3.8", + "version": "0.3.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8bf8e31..a213de6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@advanced-rest-client/arc-response", "description": "A module containing the UI regions and the logic to render and support HTTP response in Advanced REST Client.", - "version": "0.3.8", + "version": "0.3.9", "license": "Apache-2.0", "main": "index.js", "module": "index.js", diff --git a/src/lib/PrismFolding.js b/src/lib/PrismFolding.js index e7db502..923da04 100644 --- a/src/lib/PrismFolding.js +++ b/src/lib/PrismFolding.js @@ -111,7 +111,7 @@ Prism.hooks.add('brace-complete', (env) => { } code.classList.add('toggle-padding'); nodes.forEach((node) => { - const target = document.createElement('span'); + const target = document.createElement('button'); target.classList.add('toggle-target'); target.classList.add('opened'); target.title = 'Toggle visibility'; diff --git a/src/styles/Highlight.styles.js b/src/styles/Highlight.styles.js index 79419c3..00da362 100644 --- a/src/styles/Highlight.styles.js +++ b/src/styles/Highlight.styles.js @@ -61,6 +61,7 @@ pre { } .toggle-target { + all: unset; position: absolute; width: 12px; height: 12px; @@ -73,6 +74,11 @@ pre { margin-top: 0.2rem; } +.toggle-target:focus { + border: 1px solid rgb(0 95 204); + box-shadow: 0px 0px 1px 0px rgb(0 88 200 / 87%); +} + .toggle-target::before { content: '+'; } diff --git a/test/ResponseHighlightElement.test.js b/test/ResponseHighlightElement.test.js index c3ae2b2..3e59482 100644 --- a/test/ResponseHighlightElement.test.js +++ b/test/ResponseHighlightElement.test.js @@ -90,7 +90,7 @@ describe('ResponseHighlightElement', () => { await aTimeout(0); const compare = '' + - '' + + '' + '{' + '"test": true' + '}' + @@ -287,7 +287,7 @@ describe('ResponseHighlightElement', () => { await aTimeout(0); const compare = '' + - '' + + '' + '{' + '"test": true' + '}' + @@ -295,4 +295,28 @@ describe('ResponseHighlightElement', () => { assert.dom.equal(element[outputElement], compare, { ignoreAttributes: ['aria-label'] }); }); }); + + describe('test toggle button in code viewer', () => { + beforeEach(() => { + // @ts-ignore + Prism.plugins.matchBraces.resetIndex(); + }); + + it("should remove and add class on toggle button", async () => { + const element = await jsonNpFixture(); + await aTimeout(0); + const button = /** @type HTMLElement */ ( + element[outputElement].querySelector(".toggle-target") + ); + + // @ts-ignore + assert.equal(button.classList, "toggle-target opened"); + button.click(); + // @ts-ignore + assert.equal(button.classList, "toggle-target"); + button.click(); + // @ts-ignore + assert.equal(button.classList, "toggle-target opened"); + }); + }); });