Skip to content

Commit

Permalink
fix: prevent "hover" overlays from receiving focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook Johnson authored and Westbrook committed May 26, 2022
1 parent 9d07e38 commit 7bd5ac2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/overlay/src/OverlayTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ export class OverlayTrigger extends SpectrumElement {
offset: this.offset,
placement: this.placement,
receivesFocus:
this.type && this.type !== 'inline' ? 'auto' : undefined,
!this.type || this.type === 'inline' || this.open === 'hover'
? undefined
: 'auto',
};
}

Expand Down
16 changes: 15 additions & 1 deletion packages/overlay/stories/overlay.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OverlayContentTypes,
OverlayTrigger,
Placement,
TriggerInteractions,
VirtualTrigger,
} from '../';
import '@spectrum-web-components/action-button/sp-action-button.js';
Expand Down Expand Up @@ -109,6 +110,12 @@ export default {
],
},
},
type: {
control: {
type: 'inline-radio',
options: ['modal', 'replace', 'inline'],
},
},
colorStop: {
control: {
type: 'inline-radio',
Expand All @@ -127,16 +134,23 @@ interface Properties {
placement: Placement;
offset: number;
open?: OverlayContentTypes;
type?: Extract<TriggerInteractions, 'inline' | 'modal' | 'replace'>;
}

const template = ({ placement, offset, open }: Properties): TemplateResult => {
const template = ({
placement,
offset,
open,
type,
}: Properties): TemplateResult => {
return html`
${storyStyles}
<overlay-trigger
id="trigger"
placement="${placement}"
offset="${offset}"
open=${ifDefined(open)}
type=${ifDefined(type)}
>
<sp-button variant="primary" slot="trigger">Show Popover</sp-button>
<sp-popover
Expand Down
19 changes: 9 additions & 10 deletions packages/overlay/test/overlay-trigger-hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import {
aTimeout,
elementUpdated,
expect,
fixture,
html,
oneEvent,
waitUntil,
} from '@open-wc/testing';
import '@spectrum-web-components/popover/sp-popover.js';
Expand Down Expand Up @@ -143,21 +145,18 @@ describe('Overlay Trigger - Hover', () => {
expect(el.open).to.be.undefined;

const trigger = el.querySelector('[slot="trigger"]') as ActionButton;
trigger.dispatchEvent(
new Event('mouseenter', {
bubbles: true,
})
);
const opened = oneEvent(el, 'sp-opened');
trigger.focus();
await opened;

await elementUpdated(el);
await aTimeout(500);

expect(el.open).to.equal('hover');

trigger.dispatchEvent(
new Event('mouseleave', {
bubbles: true,
})
);
const closed = oneEvent(el, 'sp-closed');
trigger.blur();
await closed;

await elementUpdated(el);

Expand Down

0 comments on commit 7bd5ac2

Please sign in to comment.