Skip to content

Commit

Permalink
[DataGrid] Register getLocaleText synchronously (#8029)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw authored Feb 27, 2023
1 parent 13c7b10 commit 3149c0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { GridPrivateApiCommon } from '../../models/api/gridApiCommon';
import { GridLocaleTextApi } from '../../models/api/gridLocaleTextApi';
import { useGridApiMethod } from '../utils/useGridApiMethod';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';

export const useGridLocaleText = (
Expand All @@ -18,9 +17,7 @@ export const useGridLocaleText = (
[props.localeText],
);

const localeTextApi: GridLocaleTextApi = {
apiRef.current.register('public', {
getLocaleText,
};

useGridApiMethod(apiRef, localeTextApi, 'public');
});
};
22 changes: 22 additions & 0 deletions packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,28 @@ describe('<DataGrid /> - Layout & Warnings', () => {
);
expect(document.querySelector('[title="Ordenar"]')).not.to.equal(null);
});

it('should allow to change localeText on the fly', () => {
function TestCase(props: Partial<DataGridProps>) {
return (
<div style={{ width: 300, height: 300 }}>
<DataGrid
{...baselineProps}
components={{
Toolbar: GridToolbar,
}}
{...props}
/>
</div>
);
}
const { setProps, getByText } = render(
<TestCase localeText={{ toolbarDensity: 'Density' }} />,
);
expect(getByText('Density')).not.to.equal(null);
setProps({ localeText: { toolbarDensity: 'Densidade' } });
expect(getByText('Densidade')).not.to.equal(null);
});
});

it('should allow style customization using the theme', function test() {
Expand Down

0 comments on commit 3149c0a

Please sign in to comment.