Skip to content

Commit

Permalink
feat(core): CatDropdown improvement (#499)
Browse files Browse the repository at this point in the history
* feat(core): add property disableInitialFocus to CatDropdown, initTrigger if open method is called

* feat(core): fix linter

* feat(core): rename disableInitialFocus to noInitialFocus

---------

Co-authored-by: anastasiia_glushkova <[email protected]>
  • Loading branch information
glushkova91 and anastasiia_glushkova authored Apr 22, 2024
1 parent 0b57dd3 commit ae27bcc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions angular/projects/catalyst/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,15 @@ export declare interface CatDatepickerInline extends Components.CatDatepickerInl
}

@ProxyCmp({
inputs: ['arrowNavigation', 'noAutoClose', 'noResize', 'overflow', 'placement'],
inputs: ['arrowNavigation', 'noAutoClose', 'noInitialFocus', 'noResize', 'overflow', 'placement'],
methods: ['toggle', 'open', 'close']
})
@Component({
selector: 'cat-dropdown',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['arrowNavigation', 'noAutoClose', 'noResize', 'overflow', 'placement']
inputs: ['arrowNavigation', 'noAutoClose', 'noInitialFocus', 'noResize', 'overflow', 'placement']
})
export class CatDropdown {
protected el: HTMLElement;
Expand Down
8 changes: 8 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ export namespace Components {
* Do not close the dropdown on outside clicks.
*/
"noAutoClose": boolean;
/**
* No element in dropdown will receive focus when dropdown is open. By default, the first element in tab order will receive a focus.
*/
"noInitialFocus": boolean;
/**
* Do not change the size of the dropdown to ensure it isn’t too big to fit in the viewport (or more specifically, its clipping context).
*/
Expand Down Expand Up @@ -2756,6 +2760,10 @@ declare namespace LocalJSX {
* Do not close the dropdown on outside clicks.
*/
"noAutoClose"?: boolean;
/**
* No element in dropdown will receive focus when dropdown is open. By default, the first element in tab order will receive a focus.
*/
"noInitialFocus"?: boolean;
/**
* Do not change the size of the dropdown to ensure it isn’t too big to fit in the viewport (or more specifically, its clipping context).
*/
Expand Down
13 changes: 12 additions & 1 deletion core/src/components/cat-dropdown/cat-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export class CatDropdown {
*/
@Prop() overflow = false;

/**
* No element in dropdown will receive focus when dropdown is open.
* By default, the first element in tab order will receive a focus.
*/
@Prop() noInitialFocus = false;

/**
* Emitted when the dropdown is opened.
*/
Expand Down Expand Up @@ -99,6 +105,10 @@ export class CatDropdown {
*/
@Method()
async open(): Promise<void> {
if (!this.trigger) {
this.initTrigger();
}

if (this.isOpen === null || this.isOpen) {
return; // busy or open
}
Expand Down Expand Up @@ -145,7 +155,8 @@ export class CatDropdown {
return true;
}
return event.key === 'Tab' && event.shiftKey;
}
},
initialFocus: () => (this.noInitialFocus ? false : undefined)
});
this.trap.activate();
});
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-dropdown/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ show additional content on demand.
| ----------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| `arrowNavigation` | `arrow-navigation` | Do not navigate focus inside the dropdown via vertical arrow keys. | `"horizontal" \| "none" \| "vertical"` | `'vertical'` |
| `noAutoClose` | `no-auto-close` | Do not close the dropdown on outside clicks. | `boolean` | `false` |
| `noInitialFocus` | `no-initial-focus` | No element in dropdown will receive focus when dropdown is open. By default, the first element in tab order will receive a focus. | `boolean` | `false` |
| `noResize` | `no-resize` | Do not change the size of the dropdown to ensure it isn’t too big to fit in the viewport (or more specifically, its clipping context). | `boolean` | `false` |
| `overflow` | `overflow` | Allow overflow when dropdown is open. | `boolean` | `false` |
| `placement` | `placement` | The placement of the dropdown. | `"bottom" \| "bottom-end" \| "bottom-start" \| "left" \| "left-end" \| "left-start" \| "right" \| "right-end" \| "right-start" \| "top" \| "top-end" \| "top-start"` | `'bottom-start'` |
Expand Down
1 change: 1 addition & 0 deletions vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const CatDropdown = /*@__PURE__*/ defineContainer<JSX.CatDropdown>('cat-d
'arrowNavigation',
'noResize',
'overflow',
'noInitialFocus',
'catOpen',
'catClose'
]);
Expand Down

0 comments on commit ae27bcc

Please sign in to comment.