Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions packages/components/src/components/popover-button/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
SyncValueBySelectorPropType,
TooltipAlignPropType,
} from '../../schema';
import { validatePopoverAlign } from '../../schema';
import { validatePopoverAlign, validateShow } from '../../schema';
import type { PopoverButtonProps, PopoverButtonStates } from '../../schema/components/popover-button';
import { alignFloatingElements } from '../../utils/align-floating-elements';

Expand Down Expand Up @@ -52,13 +52,20 @@ export class KolPopoverButton implements PopoverButtonProps {
void this.refPopover?.hidePopover();
}

/**
* Show the popover programmatically by calling the native showPopover method.
*/
@Method()
// eslint-disable-next-line @typescript-eslint/require-await
public async showPopover() {
void this.refPopover?.showPopover();
}

/**
* Sets focus on the internal element.
*/
@Method()
public async kolFocus() {
// eslint-disable-next-line no-console
console.log('Focusing popover button', this.refButton);
await this.refButton?.kolFocus();
}

Expand Down Expand Up @@ -246,6 +253,11 @@ export class KolPopoverButton implements PopoverButtonProps {
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Makes the element show up.
*/
@Prop() public _show?: boolean = false;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down Expand Up @@ -282,6 +294,19 @@ export class KolPopoverButton implements PopoverButtonProps {
validatePopoverAlign(this, value);
}

@Watch('_show')
public validateShow(value?: boolean): void {
validateShow(this, value);
}

public componentDidLoad() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Es muss nach dem Render passieren: https://stenciljs.com/docs/component-lifecycle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wenn man die show prop initial auf true setzt und show- bzw. hide-popover in der componentDidRender aufruft macht dann schließt sich der popover nicht.
Wenn die prop initial auf false gesetzt wird öffnet sich der popover erst nach dem zweiten Klick.

Ist das das gewünschte verhalten ?

if (this._show) {
void this.showPopover();
} else {
void this.hidePopover();
}
}

public componentWillLoad() {
this.validatePopoverAlign(this._popoverAlign);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,37 @@ test.describe('kol-popover-button', () => {
await button.click();
await expect(tooltip).not.toBeVisible();
});

test('should be open initially when the _show prop is set to true', async ({ page }) => {
await page.setContent(`
<kol-popover-button _show _label="Toggle popover">
Popover content
</kol-popover-button>
`);

const popover = page.getByTestId('popover-content');
await expect(popover).toBeVisible();
});

test('should be closed initially when the _show prop is set to false', async ({ page }) => {
await page.setContent(`
<kol-popover-button _show="false" _label="Toggle popover">
Popover content
</kol-popover-button>
`);

const popover = page.getByTestId('popover-content');
await expect(popover).not.toBeVisible();
});

test('should be closed initially when the _show prop is not set', async ({ page }) => {
await page.setContent(`
<kol-popover-button _label="Toggle popover">
Popover content
</kol-popover-button>
`);

const popover = page.getByTestId('popover-content');
await expect(popover).not.toBeVisible();
});
});
15 changes: 15 additions & 0 deletions packages/components/src/components/popover-button/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ export class KolPopoverButton implements PopoverButtonProps {
void this.ref?.hidePopover();
}

/**
* Shows the popover programmatically by forwarding the call to the web component.
*/
@Method()
// eslint-disable-next-line @typescript-eslint/require-await
public async showPopover() {
void this.ref?.showPopover();
}

private catchRef = (ref?: HTMLKolPopoverButtonWcElement) => {
this.ref = ref;
};
Expand Down Expand Up @@ -71,6 +80,7 @@ export class KolPopoverButton implements PopoverButtonProps {
_on={this._on}
_popoverAlign={this._popoverAlign}
_shortKey={this._shortKey}
_show={this._show}
_syncValueBySelector={this._syncValueBySelector}
_tabIndex={this._tabIndex}
_tooltipAlign={this._tooltipAlign}
Expand Down Expand Up @@ -164,6 +174,11 @@ export class KolPopoverButton implements PopoverButtonProps {
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Makes the element show up.
*/
@Prop() public _show?: boolean;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/schema/components/popover-button.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Generic } from 'adopted-style-sheets';
import type { PropLabelWithExpertSlot, PropPopoverAlign } from '../props';
import type { PropLabelWithExpertSlot, PropPopoverAlign, PropShow } from '../props';
import type { OptionalButtonProps, RequiredButtonProps } from './button';

export type RequiredPopoverButtonProps = RequiredButtonProps;
export type OptionalPopoverButtonProps = OptionalButtonProps & PropPopoverAlign;
export type OptionalPopoverButtonProps = OptionalButtonProps & PropPopoverAlign & PropShow;

export type RequiredPopoverButtonStates = PropLabelWithExpertSlot;
export type OptionalPopoverButtonStates = PropPopoverAlign;
Expand Down
14 changes: 2 additions & 12 deletions packages/samples/react/src/components/popover-button/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import { KolHeading, KolPopoverButton, KolToolbar } from '@public-ui/react-v19';
import type { FC } from 'react';
import React, { useEffect } from 'react';
import React from 'react';
import { useToasterService } from '../../hooks/useToasterService';
import { SampleDescription } from '../SampleDescription';

export const PopoverButtonBasic: FC = () => {
const { dummyClickEventHandler } = useToasterService();
const buttonRef = React.useRef<HTMLKolPopoverButtonElement>(null);

useEffect(() => {
const run = async () => {
await buttonRef.current?.kolFocus();
if (buttonRef.current instanceof HTMLButtonElement) {
buttonRef.current.click();
}
};
run();
}, []);

const dummyEventHandler = {
onClick: dummyClickEventHandler,
};
Expand Down Expand Up @@ -49,7 +39,7 @@ export const PopoverButtonBasic: FC = () => {
</p>
</SampleDescription>
<div className="flex flex-col gap-4">
<KolPopoverButton _label={'Actions'} _variant="primary" _icons={{ right: 'codicon codicon-chevron-down' }} ref={buttonRef}>
<KolPopoverButton _show _label={'Actions'} _variant="primary" _icons={{ right: 'codicon codicon-chevron-down' }} ref={buttonRef}>
<KolToolbar _label="Action toolbar" _items={TOOLBAR_ITEMS} _orientation="vertical" />
</KolPopoverButton>
<KolPopoverButton _label="Help" _icons="codicon codicon-info" _popoverAlign="right" _tooltipAlign="bottom" _hideLabel>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/tools/visual-tests/tests/sample-app.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ ROUTES.set('popover-button/basic', {
zoom: {
skip: true,
},
viewportSize: {
width: 200,
height: 220,
}
},
});
ROUTES.set('progress/basic', {
Expand Down
Loading