Skip to content

Commit

Permalink
fix: use inline style
Browse files Browse the repository at this point in the history
  • Loading branch information
kl-nevermore committed Jan 11, 2024
1 parent 5c6dfa7 commit de0111c
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions components/lib/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const DataTable = React.forwardRef((inProps, ref) => {
const dropPosition = React.useRef(null);
const styleElement = React.useRef(null);
const responsiveStyleElement = React.useRef(null);
const beforeResizeStyleElement = React.useRef(null);

const columnWidthsState = React.useRef(null);
const tableWidthState = React.useRef(null);
const resizeColumn = React.useRef(null);
Expand Down Expand Up @@ -504,6 +506,7 @@ export const DataTable = React.forwardRef((inProps, ref) => {
};

const onColumnResizeStart = (e) => {
createBeforeResizeStyleElement();
const { originalEvent: event, column } = e;
const containerLeft = DomHandler.getOffset(elementRef.current).left;

Expand All @@ -518,9 +521,8 @@ export const DataTable = React.forwardRef((inProps, ref) => {
const onColumnResize = (event) => {
const containerLeft = DomHandler.getOffset(elementRef.current).left;

DomHandler.addStyles(elementRef.current, {
userSelect: 'none'
});
elementRef.current.setAttribute('data-p-unselectable-text', true);

resizeHelperRef.current.style.height = elementRef.current.offsetHeight + 'px';
resizeHelperRef.current.style.top = 0 + 'px';
resizeHelperRef.current.style.left = event.pageX - containerLeft + elementRef.current.scrollLeft + 'px';
Expand Down Expand Up @@ -579,9 +581,8 @@ export const DataTable = React.forwardRef((inProps, ref) => {
resizeHelperRef.current.style.display = 'none';
resizeColumn.current = null;
resizeColumnElement.current = null;

elementRef.current.style.removeProperty('user-select');

elementRef.current.setAttribute('data-p-unselectable-text', 'true');
destroyBeforeResizeStyleElement();
unbindColumnResizeEvents();
};

Expand Down Expand Up @@ -791,6 +792,17 @@ export const DataTable = React.forwardRef((inProps, ref) => {
}
};

const createBeforeResizeStyleElement = () => {
beforeResizeStyleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);
let innerHTML = `
[data-pc-name="datatable"][${attributeSelector.current}] {
user-select:none;
}
`;

beforeResizeStyleElement.current.innerHTML = innerHTML;
};

const createStyleElement = () => {
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);
};
Expand Down Expand Up @@ -844,6 +856,10 @@ export const DataTable = React.forwardRef((inProps, ref) => {
styleElement.current = DomHandler.removeInlineStyle(styleElement.current);
};

const destroyBeforeResizeStyleElement = () => {
beforeResizeStyleElement.current = DomHandler.removeInlineStyle(beforeResizeStyleElement.current);
};

const onPageChange = (e) => {
clearEditingMetaData();

Expand Down Expand Up @@ -1469,6 +1485,7 @@ export const DataTable = React.forwardRef((inProps, ref) => {
unbindColumnResizeEvents();
destroyStyleElement();
destroyResponsiveStyle();
destroyBeforeResizeStyleElement();
});

React.useImperativeHandle(ref, () => ({
Expand Down

0 comments on commit de0111c

Please sign in to comment.