-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract common scroller logic to reusable mixin
- Loading branch information
1 parent
e133961
commit a0804f5
Showing
5 changed files
with
79 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2020 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import type { Constructor } from '@open-wc/dedupe-mixin'; | ||
import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js'; | ||
|
||
export declare function ScrollerMixin<T extends Constructor<HTMLElement>>( | ||
base: T, | ||
): Constructor<FocusMixinClass> & Constructor<ScrollerMixinClass> & T; | ||
|
||
export declare class ScrollerMixinClass { | ||
/** | ||
* This property indicates the scroll direction. Supported values are `vertical`, `horizontal`, `none`. | ||
* When `scrollDirection` is undefined scrollbars will be shown in both directions. | ||
* @attr {string} scroll-direction | ||
*/ | ||
scrollDirection: 'horizontal' | 'none' | 'vertical' | undefined; | ||
|
||
/** | ||
* Indicates whether the element can be focused and where it participates in sequential keyboard navigation. | ||
*/ | ||
tabindex: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2020 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js'; | ||
|
||
/** | ||
* @polymerMixin | ||
* @mixes FocusMixin | ||
*/ | ||
export const ScrollerMixin = (superClass) => | ||
class ScrollerMixinClass extends FocusMixin(superClass) { | ||
static get properties() { | ||
return { | ||
/** | ||
* This property indicates the scroll direction. Supported values are `vertical`, `horizontal`, `none`. | ||
* When `scrollDirection` is undefined scrollbars will be shown in both directions. | ||
* @attr {string} scroll-direction | ||
*/ | ||
scrollDirection: { | ||
type: String, | ||
reflectToAttribute: true, | ||
}, | ||
|
||
/** | ||
* Indicates whether the element can be focused and where it participates in sequential keyboard navigation. | ||
* @protected | ||
*/ | ||
tabindex: { | ||
type: Number, | ||
value: 0, | ||
reflectToAttribute: true, | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Override method inherited from `FocusMixin` to mark the scroller as focused | ||
* only when the host is focused. | ||
* @param {Event} event | ||
* @return {boolean} | ||
* @protected | ||
*/ | ||
_shouldSetFocus(event) { | ||
return event.target === this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters