Skip to content

Commit

Permalink
ONL-7032 Adds popover inject functionality (#1375)
Browse files Browse the repository at this point in the history
* Adds popover inject functionality

* Expose overlayContent container

* Added overlay expose test

* Added export of Symbol

* 2.1.29
  • Loading branch information
Derrick Greyvensteyn authored Dec 5, 2022
1 parent 682fa14 commit 94e641e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ebury/chameleon-components",
"version": "2.1.28",
"version": "2.1.29",
"main": "src/main.js",
"sideEffects": false,
"author": "Ebury Team (http://labs.ebury.rocks/)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('EcFullScreenOverlay', () => {
expect(document.activeElement).toEqual(wrapper.findByDataTest('ec-full-screen-overlay__close-icon-btn').element);
});

describe('defineExpose', () => {
it('should return the container that was exposed', () => {
const wrapper = mountFullScreenOverlay();
const container = wrapper.vm.getFocusTrapContainer();
const { overlayContent } = wrapper.vm;
expect(container).toEqual(overlayContent);
});
});

describe(':props', () => {
it(':show - should not render the overlay when is false', () => {
const wrapper = mountFullScreenOverlay({ show: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ const { deactivate } = useFocusTrap(overlayContent, {
allowOutsideClick: true,
});
function getFocusTrapContainer() {
return overlayContent.value;
}
defineExpose({
getFocusTrapContainer,
});
onUnmounted(() => {
deactivate();
});
Expand Down
13 changes: 13 additions & 0 deletions src/components/ec-popover/__snapshots__/ec-popover.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ exports[`EcPopover component should add the z-index level class if the level was
>
</fv-dropdown-stub>
`;

exports[`EcPopover component should attach to a different element when provided 1`] = `
<fv-dropdown-stub
ariaid="ec-popover-1"
arrowoverflow="true"
container="custom-element"
data-test="ec-popover"
popperclass="ec-popover"
>
</fv-dropdown-stub>
`;

Expand Down
1 change: 1 addition & 0 deletions src/components/ec-popover/ec-popover-provide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const POPOVER_CONTAINER_KEY = Symbol('popoverContainer');
14 changes: 14 additions & 0 deletions src/components/ec-popover/ec-popover.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { mount } from '@vue/test-utils';
import { ref } from 'vue';

import EcPopover from './ec-popover.vue';
import { POPOVER_CONTAINER_KEY } from './ec-popover-provide';

describe('EcPopover component', () => {
function mountEcPopover(props, mountOpts) {
Expand Down Expand Up @@ -53,4 +55,16 @@ describe('EcPopover component', () => {
const wrapper = mountEcPopover();
expect(typeof wrapper.vm.update).toBe('function');
});

it('should attach to a different element when provided', () => {
const wrapper = mount(EcPopover, {
global: {
stubs: { FvDropdown: true },
provide: {
[POPOVER_CONTAINER_KEY]: { container: ref('custom-element') },
},
},
});
expect(wrapper.element).toMatchSnapshot();
});
});
8 changes: 6 additions & 2 deletions src/components/ec-popover/ec-popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export default {

<script setup>
import { Dropdown as FvDropdown } from 'floating-vue';
import { ref, toRefs, useAttrs } from 'vue';
import {
inject, ref, toRefs, useAttrs,
} from 'vue';
import { getUid } from '../../utils/uid';
import { POPOVER_CONTAINER_KEY } from './ec-popover-provide';
const attrs = useAttrs();
const props = defineProps({
Expand All @@ -42,11 +45,12 @@ const id = getUid();
const popover = ref(null);
const { level, popperClass } = toRefs(props);
const { container: containerInject } = inject(POPOVER_CONTAINER_KEY, { container: ref('body') });
function getOptions() {
return {
popperClass: `${popperClass.value} ec-popover${level.value && ` ec-popover--${level.value}`}`.trim(),
container: 'body',
container: containerInject.value,
ariaId: `ec-popover-${id}`,
arrowOverflow: true, // to hide the arrow for popover
...attrs,
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export { default as EcNavigationLink } from './components/ec-navigation-link';
export { default as EcPanel } from './components/ec-panel';
export { default as EcPhoneNumberInput } from './components/ec-phone-number-input';
export { default as EcPopover } from './components/ec-popover';
export { POPOVER_CONTAINER_KEY } from './components/ec-popover/ec-popover-provide';
export { default as EcPrivacyPolicy } from './components/ec-privacy-policy';
export { default as EcSmartTable } from './components/ec-smart-table';
export { default as EcSubmenu } from './components/ec-submenu';
Expand Down

1 comment on commit 94e641e

@vercel
Copy link

@vercel vercel bot commented on 94e641e Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chameleon – ./

chameleon-git-master-ebury.vercel.app
chameleon-ebury.vercel.app
chameleon-dead-plane.vercel.app

Please sign in to comment.