Skip to content

Commit 89bd5e5

Browse files
Ypatadia/pagination default fix/eng 158360 (#1032)
* fix: removed default value of aria-level in <Dialog/> * fix: default value to pass to toLocaleString() * fix: unit test * fix: changed toLocaleString to pager object * fix: added length * fix: added default value to getPageCount
1 parent bab2431 commit 89bd5e5

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

src/components/Dialog/BaseDialog/BaseDialog.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const BaseDialog: FC<BaseDialogProps> = React.forwardRef(
4444
headerButtonProps,
4545
headerClassNames,
4646
headerIcon = IconName.mdiArrowLeftThick,
47-
headingLevel = 1,
47+
headingLevel,
4848
height,
4949
lastFocusableSelector,
5050
maskClosable = true,
@@ -154,10 +154,11 @@ export const BaseDialog: FC<BaseDialogProps> = React.forwardRef(
154154
<div className={headerClasses}>
155155
<span
156156
id={labelId}
157-
{...(header && {
158-
role: "heading",
159-
"aria-level": headingLevel
160-
})}
157+
{...(header &&
158+
headingLevel !== undefined && {
159+
role: 'heading',
160+
'aria-level': headingLevel,
161+
})}
161162
>
162163
{headerButtonProps && (
163164
<Button

src/components/Dialog/Dialog.test.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,68 @@ describe('Dialog', () => {
116116
false
117117
);
118118
});
119+
120+
test('Should render header without heading attributes when headingLevel is undefined', () => {
121+
wrapper.setProps({
122+
visible: true,
123+
header,
124+
body,
125+
// headingLevel is undefined by default
126+
});
127+
128+
// Find the header span element
129+
const headerSpan = wrapper.find('.header span').first();
130+
131+
// Should not have role="heading" or aria-level attributes when headingLevel is undefined
132+
expect(headerSpan.prop('role')).toBeUndefined();
133+
expect(headerSpan.prop('aria-level')).toBeUndefined();
134+
});
135+
136+
test('Should render header with heading attributes when headingLevel is provided', () => {
137+
wrapper.setProps({
138+
visible: true,
139+
header,
140+
body,
141+
headingLevel: 2,
142+
});
143+
144+
// Find the header span element
145+
const headerSpan = wrapper.find('.header span').first();
146+
147+
// Should have role="heading" and aria-level attributes when headingLevel is provided
148+
expect(headerSpan.prop('role')).toBe('heading');
149+
expect(headerSpan.prop('aria-level')).toBe(2);
150+
});
151+
152+
test('Should not apply heading attributes when header is not provided even if headingLevel is set', () => {
153+
wrapper.setProps({
154+
visible: true,
155+
// No header prop
156+
body,
157+
headingLevel: 3,
158+
});
159+
160+
// Find the header span element
161+
const headerSpan = wrapper.find('.header span').first();
162+
163+
// Should not have heading attributes when header prop is not provided
164+
expect(headerSpan.prop('role')).toBeUndefined();
165+
expect(headerSpan.prop('aria-level')).toBeUndefined();
166+
});
167+
168+
test('Should handle headingLevel of 0 correctly', () => {
169+
wrapper.setProps({
170+
visible: true,
171+
header,
172+
body,
173+
headingLevel: 0, // Edge case: headingLevel is 0 (falsy but valid)
174+
});
175+
176+
// Find the header span element
177+
const headerSpan = wrapper.find('.header span').first();
178+
179+
// Should still apply heading attributes when headingLevel is 0 (since !== undefined)
180+
expect(headerSpan.prop('role')).toBe('heading');
181+
expect(headerSpan.prop('aria-level')).toBe(0);
182+
});
119183
});

src/components/Dialog/Dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const Dialog: FC<DialogProps> = React.forwardRef(
4242
headerButtonProps,
4343
headerClassNames,
4444
headerIcon,
45-
headingLevel=1,
45+
headingLevel,
4646
height,
4747
locale = enUS,
4848
okButtonProps,

src/components/Pagination/Pagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export const Pagination: FC<PaginationProps> = React.forwardRef(
247247
};
248248

249249
const getPageCount = (): number => {
250-
let pages: number;
250+
let pages: number = 0;
251251

252252
if (total) {
253253
pages = Math.ceil(total / _pageSize);

0 commit comments

Comments
 (0)