Skip to content

Commit

Permalink
feat: add zIndex prop for Modal (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyadeorukhkar authored Jul 28, 2023
1 parent d04e392 commit ebd3cbd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-bottles-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/blade": patch
---

feat: add zIndex prop for Modal
8 changes: 7 additions & 1 deletion packages/blade/src/components/Modal/Modal.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type ModalProps = {
* Accessibility label for the modal
*/
accessibilityLabel?: string;
/**
* Sets the z-index of the modal
* @default 1000
*/
zIndex?: number;
};

const entry = keyframes`
Expand Down Expand Up @@ -100,6 +105,7 @@ const Modal = ({
initialFocusRef,
size = 'small',
accessibilityLabel,
zIndex = modalHighestZIndex,
}: ModalProps): React.ReactElement => {
const { theme, platform } = useTheme();
const { isMounted, isVisible } = usePresence(isOpen, {
Expand Down Expand Up @@ -164,7 +170,7 @@ const Modal = ({
context={context}
modal={true}
>
<Box zIndex={modalHighestZIndex} position="fixed" testID="modal-wrapper">
<Box zIndex={zIndex} position="fixed" testID="modal-wrapper">
<ModalBackdrop />
<ModalContent
{...metaAttribute({
Expand Down
14 changes: 14 additions & 0 deletions packages/blade/src/components/Modal/__tests__/Modal.web.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,18 @@ describe('Modal', () => {
);
mockConsoleError.mockRestore();
});

it('renders a Modal with custom zIndex', () => {
const { getByTestId } = renderWithTheme(
<Modal isOpen={true} onDismiss={() => {}} accessibilityLabel="Test Modal" zIndex={9999}>
<ModalBody>
<Text>Test Content</Text>
</ModalBody>
</Modal>,
);
const container = getByTestId('modal-wrapper');
expect(container).toHaveStyle({
zIndex: 9999,
});
});
});
8 changes: 8 additions & 0 deletions packages/blade/src/components/Modal/docs/ModalDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ const ModalDocs = (): JSX.Element => {
<Code>{'<ModalHeader />'}</Code>]
</Text>
),
zIndex: (
<Text size="small" type="subdued">
<Text size="small" type="subdued">
<Code size="medium">number</Code>
</Text>
Sets the z-index of the modal
</Text>
),
}}
/>
<Heading size="medium">ModalHeader Props</Heading>
Expand Down

0 comments on commit ebd3cbd

Please sign in to comment.