Skip to content

Commit

Permalink
fix: #6682 (#7247)
Browse files Browse the repository at this point in the history
* fix: #6682

- Ensure element styles set via pt merge with required `xBarRef` and `yBarRef` styles

The following styles for "barX" can not be overridden:
 - width
 - left
 - bottom

 The following styles for "barY" can not be overridden:
 - height
 - top
 - right

* Make use of `DomHandler.applyStyle`method

- Fix static method to properly make use of `style` parameter
- Update typing

* Update typing to include `string` as an option
  • Loading branch information
gcko authored Sep 25, 2024
1 parent 96c10f8 commit dfe5e9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions components/lib/scrollpanel/ScrollPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@ export const ScrollPanel = React.forwardRef((inProps, ref) => {
DomHandler.addClass(xBarRef.current, 'p-scrollpanel-hidden');
} else {
DomHandler.removeClass(xBarRef.current, 'p-scrollpanel-hidden');
xBarRef.current.style.cssText = 'width:' + Math.max(scrollXRatio.current * 100, 10) + '%; left:' + (contentRef.current.scrollLeft / totalWidth) * 100 + '%;bottom:' + bottom + 'px;';
DomHandler.applyStyle(xBarRef.current, {
width: Math.max(scrollXRatio.current * 100, 10) + '%',
left: (contentRef.current.scrollLeft / totalWidth) * 100 + '%',
bottom: bottom + 'px'
});
}

if (scrollYRatio.current >= 1) {
DomHandler.addClass(yBarRef.current, 'p-scrollpanel-hidden');
} else {
DomHandler.removeClass(yBarRef.current, 'p-scrollpanel-hidden');
yBarRef.current.style.cssText = 'height:' + Math.max(scrollYRatio.current * 100, 10) + '%; top: calc(' + (contentRef.current.scrollTop / totalHeight) * 100 + '% - ' + xBarRef.current.clientHeight + 'px);right:' + right + 'px;';
DomHandler.applyStyle(yBarRef.current, {
height: Math.max(scrollYRatio.current * 100, 10) + '%',
top: 'calc(' + (contentRef.current.scrollTop / totalHeight) * 100 + '% - ' + xBarRef.current.clientHeight + 'px)',
right: right + 'px'
});
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,9 @@ export default class DomHandler {

static applyStyle(element, style) {
if (typeof style === 'string') {
element.style.cssText = this.style;
element.style.cssText = style;
} else {
for (let prop in this.style) {
for (let prop in style) {
element.style[prop] = style[prop];
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/utils/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export declare class DomHandler {
static getCursorOffset(el: HTMLElement, prevText?: string, nextText?: string, currentText?: string): { top: any; left: any };
static invokeElementMethod(el: HTMLElement, methodName: string, arg: any): void;
static isClickable(el: HTMLElement): boolean;
static applyStyle(el: HTMLElement, style: any): void;
static applyStyle(el: HTMLElement, style: React.CSSProperties | string): void;
static exportCSV(csv: any, filename: string): void;
static saveAs(file: { name: string; url: any }): boolean;
static createInlineStyle(nonce?: string, styleContainer?: ShadowRoot | HTMLElement): HTMLStyleElement;
Expand Down

0 comments on commit dfe5e9f

Please sign in to comment.