Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/categroy-filter): add filter cleared event #1562

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion packages/angular/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class IxCategoryFilter {
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
proxyOutputs(this, this.el, ['categoryChanged', 'inputChanged', 'filterChanged']);
proxyOutputs(this, this.el, ['categoryChanged', 'inputChanged', 'filterChanged', 'filterCleared']);
}
}

Expand All @@ -385,6 +385,10 @@ export declare interface IxCategoryFilter extends Components.IxCategoryFilter {
* Event dispatched whenever the filter state changes.
*/
filterChanged: EventEmitter<CustomEvent<IIxCategoryFilterFilterState>>;
/**
* Event dispatched whenever the filter gets cleared.
*/
filterCleared: EventEmitter<CustomEvent<void>>;
}


Expand Down
14 changes: 14 additions & 0 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,20 @@
"docs": "Event dispatched whenever the filter state changes.",
"docsTags": []
},
{
"event": "filterCleared",
"detail": "void",
"bubbles": true,
"complexType": {
"original": "void",
"resolved": "void",
"references": {}
},
"cancelable": true,
"composed": true,
"docs": "Event dispatched whenever the filter gets cleared.",
"docsTags": []
},
{
"event": "inputChanged",
"detail": "InputState",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,7 @@ declare global {
"categoryChanged": string;
"inputChanged": InputState;
"filterChanged": FilterState;
"filterCleared": void;
}
interface HTMLIxCategoryFilterElement extends Components.IxCategoryFilter, HTMLStencilElement {
addEventListener<K extends keyof HTMLIxCategoryFilterElementEventMap>(type: K, listener: (this: HTMLIxCategoryFilterElement, ev: IxCategoryFilterCustomEvent<HTMLIxCategoryFilterElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -4493,6 +4494,10 @@ declare namespace LocalJSX {
* Event dispatched whenever the filter state changes.
*/
"onFilterChanged"?: (event: IxCategoryFilterCustomEvent<FilterState>) => void;
/**
* Event dispatched whenever the filter gets cleared.
*/
"onFilterCleared"?: (event: IxCategoryFilterCustomEvent<void>) => void;
/**
* Event dispatched whenever the text input changes.
*/
Expand Down
22 changes: 19 additions & 3 deletions packages/core/src/components/category-filter/category-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export class CategoryFilter {
*/
@Event() filterChanged!: EventEmitter<FilterState>;

/**
* Event dispatched whenever the filter gets cleared.
*/
@Event() filterCleared!: EventEmitter<void>;

get dropdown() {
return this.hostElement.shadowRoot!.querySelector('ix-dropdown');
}
Expand Down Expand Up @@ -213,7 +218,8 @@ export class CategoryFilter {
this.formKeyDownListener = addDisposableEventListener(
this.formElement,
'keydown',
() => this.handleFormElementKeyDown
((e: KeyboardEvent) =>
this.handleFormElementKeyDown(e)) as EventListener
);

this.preventDefaultListener = addDisposableEventListener(
Expand All @@ -233,7 +239,7 @@ export class CategoryFilter {
this.inputKeyDownListener = addDisposableEventListener(
this.textInput.current,
'keydown',
() => this.handleInputElementKeyDown
((e: KeyboardEvent) => this.handleInputElementKeyDown(e)) as EventListener
);

this.focusInListener = addDisposableEventListener(
Expand Down Expand Up @@ -393,7 +399,10 @@ export class CategoryFilter {

case 'Enter':
case 'NumpadEnter':
this.addToken(this.inputValue, this.category);
this.addToken(
this.inputValue,
this.category || this.ID_CUSTOM_FILTER_VALUE
);
e.preventDefault();
break;
}
Expand Down Expand Up @@ -482,13 +491,20 @@ export class CategoryFilter {
}

private resetFilter(e: Event) {
const { defaultPrevented } = this.filterCleared.emit();

if (defaultPrevented) {
return;
}

e.stopPropagation();
this.closeDropdown();
this.filterTokens = [];
if (this.category) {
this.category = '';
this.categoryChanged.emit(undefined);
}

this.emitFilterEvent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ test.describe('category-preview test', () => {
});
});

test('add token', async ({ page }) => {
const token = 'Test';
await page.waitForSelector('ix-category-filter');
const input = await page.locator('input').first();
await input.click();
await input.fill(token);
await page.keyboard.press('Enter');
const chip = await page.locator('ix-filter-chip').first();
await expect(chip).toContainText(token);
});

test('clear category-preview', async ({ page }) => {
await page.waitForSelector('ix-category-filter');
await page.locator('input').first().click();
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export const IxCategoryFilter = /*@__PURE__*/ defineContainer<JSX.IxCategoryFilt
'i18nPlainText',
'categoryChanged',
'inputChanged',
'filterChanged'
'filterChanged',
'filterCleared'
]);


Expand Down
Loading