From 7549e50fe4a8c34528d09eab1a204ee8c9b7e166 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Sun, 5 Feb 2023 12:06:06 -0500 Subject: [PATCH] fix positioning of native inputs; closes #1169 --- docs/resources/changelog.md | 1 + src/components/checkbox/checkbox.styles.ts | 1 + src/components/checkbox/checkbox.test.ts | 15 +++++++++++++++ src/components/switch/switch.styles.ts | 1 + src/components/switch/switch.test.ts | 15 +++++++++++++++ 5 files changed, 33 insertions(+) diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 4ea4f66ba..84c63e691 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -13,6 +13,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti - Fixed a bug in `` that prevented `sl-change` and `sl-input` from emitting when using the eye dropper [#1157](https://github.com/shoelace-style/shoelace/issues/1157) - Fixed a bug in `` that prevented keyboard users from selecting menu items when using the keyboard [#1165](https://github.com/shoelace-style/shoelace/issues/1165) - Fixed a bug in the template for `` that caused the `form-control-help-text` part to not be in the same location as other form controls [#1178](https://github.com/shoelace-style/shoelace/issues/1178) +- Fixed a bug in `` and `` that caused the browser to scroll incorrectly when focusing on a control in a container with overflow [#1169](https://github.com/shoelace-style/shoelace/issues/1169) ## 2.0.0 diff --git a/src/components/checkbox/checkbox.styles.ts b/src/components/checkbox/checkbox.styles.ts index 3d664ca81..6dd016001 100644 --- a/src/components/checkbox/checkbox.styles.ts +++ b/src/components/checkbox/checkbox.styles.ts @@ -9,6 +9,7 @@ export default css` } .checkbox { + position: relative; display: inline-flex; align-items: top; font-family: var(--sl-input-font-family); diff --git a/src/components/checkbox/checkbox.test.ts b/src/components/checkbox/checkbox.test.ts index fd478fd53..43a1138d3 100644 --- a/src/components/checkbox/checkbox.test.ts +++ b/src/components/checkbox/checkbox.test.ts @@ -94,6 +94,21 @@ describe('', () => { await el.updateComplete; }); + it('should hide the native input with the correct positioning to scroll correctly when contained in an overflow', async () => { + // + // See: https://github.com/shoelace-style/shoelace/issues/1169 + // + const el = await fixture(html` `); + const label = el.shadowRoot!.querySelector('.checkbox')!; + const input = el.shadowRoot!.querySelector('.checkbox__input')!; + + const labelPosition = getComputedStyle(label).position; + const inputPosition = getComputedStyle(input).position; + + expect(labelPosition).to.equal('relative'); + expect(inputPosition).to.equal('absolute'); + }); + describe('when submitting a form', () => { it('should submit the correct value when a value is provided', async () => { const form = await fixture(html` diff --git a/src/components/switch/switch.styles.ts b/src/components/switch/switch.styles.ts index 851713a7b..45b682e46 100644 --- a/src/components/switch/switch.styles.ts +++ b/src/components/switch/switch.styles.ts @@ -33,6 +33,7 @@ export default css` } .switch { + position: relative; display: inline-flex; align-items: center; font-family: var(--sl-input-font-family); diff --git a/src/components/switch/switch.test.ts b/src/components/switch/switch.test.ts index 738b6db4d..cc2902c3a 100644 --- a/src/components/switch/switch.test.ts +++ b/src/components/switch/switch.test.ts @@ -113,6 +113,21 @@ describe('', () => { await el.updateComplete; }); + it('should hide the native input with the correct positioning to scroll correctly when contained in an overflow', async () => { + // + // See: https://github.com/shoelace-style/shoelace/issues/1169 + // + const el = await fixture(html` `); + const label = el.shadowRoot!.querySelector('.switch')!; + const input = el.shadowRoot!.querySelector('.switch__input')!; + + const labelPosition = getComputedStyle(label).position; + const inputPosition = getComputedStyle(input).position; + + expect(labelPosition).to.equal('relative'); + expect(inputPosition).to.equal('absolute'); + }); + describe('when submitting a form', () => { it('should submit the correct value when a value is provided', async () => { const form = await fixture(html`