Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build-tools/utils/custom-css-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const customCssPropertiesList = [
// Dropdown Custom Properties
'dropdownDefaultMaxWidth',
'dropdownDefaultMinWidth',
// Modal Custom Properties
'modalCustomWidth',
'modalCustomHeight',
// Spinner Custom Properties
'spinnerRotatorFrom',
'spinnerRotatorTo',
Expand Down
66 changes: 66 additions & 0 deletions pages/modal/custom-dimensions.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import { Button, Checkbox, FormField, Input, Modal, SpaceBetween } from '~components';

import { useAppContext } from '../app/app-context';
import { SimplePage } from '../app/templates';
import ScreenshotArea from '../utils/screenshot-area';

export default function () {
const { urlParams, setUrlParams } = useAppContext();
const [visible, setVisible] = useState(false);
const showFooter = urlParams.footer ? true : false;
const footer = <Button variant="primary">OK</Button>;

return (
<SimplePage
title="Modal with custom dimensions"
settings={
<SpaceBetween size="m">
<FormField label="Width (px)">
<Input
value={urlParams.width ? String(urlParams.width) : ''}
onChange={e => setUrlParams({ width: e.detail.value })}
type="number"
/>
</FormField>
<FormField label="Height (px)">
<Input
value={urlParams.height ? String(urlParams.height) : ''}
onChange={e => setUrlParams({ height: e.detail.value })}
type="number"
/>
</FormField>
<Checkbox checked={showFooter} onChange={e => setUrlParams({ footer: e.detail.checked })}>
Show footer
</Checkbox>
</SpaceBetween>
}
>
<Button data-testid="modal-trigger" onClick={() => setVisible(true)}>
Show modal
</Button>
<ScreenshotArea>
<Modal
header="Custom dimensions modal"
visible={visible}
onDismiss={() => setVisible(false)}
width={Number(urlParams.width) || undefined}
height={Number(urlParams.height) || undefined}
footer={showFooter ? footer : undefined}
>
{Array(100)
.fill(0)
.map((value, index) => (
<div key={index}>
<span>Text content {index}</span>
</div>
))}
<input data-testid="final-input" />
</Modal>
</ScreenshotArea>
</SimplePage>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17503,6 +17503,15 @@ The function will be called when a user clicks on the trigger button.",
"optional": true,
"type": "((options: { abortSignal: AbortSignal; }) => Promise<HTMLElement>)",
},
{
"description": "Specifies the height of the modal. When provided, the modal content becomes scrollable if it exceeds the specified height.
If the specified height exceeds available viewport space, the modal will use the maximum available space.
To make sure the content is accessible, the component will apply a minimum height of 60px for the content area,
plus the header height and the footer height.",
"name": "height",
"optional": true,
"type": "number",
},
{
"deprecatedTag": "The usage of the \`id\` attribute is reserved for internal use cases. For testing and other use cases,
use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes). If you must
Expand Down Expand Up @@ -17589,6 +17598,14 @@ Set this property to \`true\` to show them.",
"optional": false,
"type": "boolean",
},
{
"description": "Specifies the width of the modal. When provided, takes precedence over the \`size\` property.
If the specified width exceeds available viewport space, the modal will use the maximum available space.
The minimum width is 320px (equivalent to the \`small\` size).",
"name": "width",
"optional": true,
"type": "number",
},
],
"regions": [
{
Expand Down
144 changes: 72 additions & 72 deletions src/input/__tests__/__snapshots__/styles.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

exports[`getInputStyles handles all possible style configurations 1`] = `
{
"--awsui-style-background-default-c5ek4l": undefined,
"--awsui-style-background-disabled-c5ek4l": undefined,
"--awsui-style-background-focus-c5ek4l": undefined,
"--awsui-style-background-hover-c5ek4l": undefined,
"--awsui-style-background-readonly-c5ek4l": undefined,
"--awsui-style-border-color-default-c5ek4l": undefined,
"--awsui-style-border-color-disabled-c5ek4l": undefined,
"--awsui-style-border-color-focus-c5ek4l": undefined,
"--awsui-style-border-color-hover-c5ek4l": undefined,
"--awsui-style-border-color-readonly-c5ek4l": undefined,
"--awsui-style-box-shadow-default-c5ek4l": undefined,
"--awsui-style-box-shadow-disabled-c5ek4l": undefined,
"--awsui-style-box-shadow-focus-c5ek4l": undefined,
"--awsui-style-box-shadow-hover-c5ek4l": undefined,
"--awsui-style-box-shadow-readonly-c5ek4l": undefined,
"--awsui-style-color-default-c5ek4l": undefined,
"--awsui-style-color-disabled-c5ek4l": undefined,
"--awsui-style-color-focus-c5ek4l": undefined,
"--awsui-style-color-hover-c5ek4l": undefined,
"--awsui-style-color-readonly-c5ek4l": undefined,
"--awsui-style-placeholder-color-c5ek4l": undefined,
"--awsui-style-placeholder-font-size-c5ek4l": undefined,
"--awsui-style-placeholder-font-style-c5ek4l": undefined,
"--awsui-style-placeholder-font-weight-c5ek4l": undefined,
"--awsui-style-background-default-n6lfw8": undefined,
"--awsui-style-background-disabled-n6lfw8": undefined,
"--awsui-style-background-focus-n6lfw8": undefined,
"--awsui-style-background-hover-n6lfw8": undefined,
"--awsui-style-background-readonly-n6lfw8": undefined,
"--awsui-style-border-color-default-n6lfw8": undefined,
"--awsui-style-border-color-disabled-n6lfw8": undefined,
"--awsui-style-border-color-focus-n6lfw8": undefined,
"--awsui-style-border-color-hover-n6lfw8": undefined,
"--awsui-style-border-color-readonly-n6lfw8": undefined,
"--awsui-style-box-shadow-default-n6lfw8": undefined,
"--awsui-style-box-shadow-disabled-n6lfw8": undefined,
"--awsui-style-box-shadow-focus-n6lfw8": undefined,
"--awsui-style-box-shadow-hover-n6lfw8": undefined,
"--awsui-style-box-shadow-readonly-n6lfw8": undefined,
"--awsui-style-color-default-n6lfw8": undefined,
"--awsui-style-color-disabled-n6lfw8": undefined,
"--awsui-style-color-focus-n6lfw8": undefined,
"--awsui-style-color-hover-n6lfw8": undefined,
"--awsui-style-color-readonly-n6lfw8": undefined,
"--awsui-style-placeholder-color-n6lfw8": undefined,
"--awsui-style-placeholder-font-size-n6lfw8": undefined,
"--awsui-style-placeholder-font-style-n6lfw8": undefined,
"--awsui-style-placeholder-font-weight-n6lfw8": undefined,
"borderRadius": undefined,
"borderWidth": undefined,
"fontSize": undefined,
Expand All @@ -37,30 +37,30 @@ exports[`getInputStyles handles all possible style configurations 1`] = `

exports[`getInputStyles handles all possible style configurations 2`] = `
{
"--awsui-style-background-default-c5ek4l": undefined,
"--awsui-style-background-disabled-c5ek4l": undefined,
"--awsui-style-background-focus-c5ek4l": undefined,
"--awsui-style-background-hover-c5ek4l": undefined,
"--awsui-style-background-readonly-c5ek4l": undefined,
"--awsui-style-border-color-default-c5ek4l": undefined,
"--awsui-style-border-color-disabled-c5ek4l": undefined,
"--awsui-style-border-color-focus-c5ek4l": undefined,
"--awsui-style-border-color-hover-c5ek4l": undefined,
"--awsui-style-border-color-readonly-c5ek4l": undefined,
"--awsui-style-box-shadow-default-c5ek4l": undefined,
"--awsui-style-box-shadow-disabled-c5ek4l": undefined,
"--awsui-style-box-shadow-focus-c5ek4l": undefined,
"--awsui-style-box-shadow-hover-c5ek4l": undefined,
"--awsui-style-box-shadow-readonly-c5ek4l": undefined,
"--awsui-style-color-default-c5ek4l": undefined,
"--awsui-style-color-disabled-c5ek4l": undefined,
"--awsui-style-color-focus-c5ek4l": undefined,
"--awsui-style-color-hover-c5ek4l": undefined,
"--awsui-style-color-readonly-c5ek4l": undefined,
"--awsui-style-placeholder-color-c5ek4l": undefined,
"--awsui-style-placeholder-font-size-c5ek4l": undefined,
"--awsui-style-placeholder-font-style-c5ek4l": undefined,
"--awsui-style-placeholder-font-weight-c5ek4l": undefined,
"--awsui-style-background-default-n6lfw8": undefined,
"--awsui-style-background-disabled-n6lfw8": undefined,
"--awsui-style-background-focus-n6lfw8": undefined,
"--awsui-style-background-hover-n6lfw8": undefined,
"--awsui-style-background-readonly-n6lfw8": undefined,
"--awsui-style-border-color-default-n6lfw8": undefined,
"--awsui-style-border-color-disabled-n6lfw8": undefined,
"--awsui-style-border-color-focus-n6lfw8": undefined,
"--awsui-style-border-color-hover-n6lfw8": undefined,
"--awsui-style-border-color-readonly-n6lfw8": undefined,
"--awsui-style-box-shadow-default-n6lfw8": undefined,
"--awsui-style-box-shadow-disabled-n6lfw8": undefined,
"--awsui-style-box-shadow-focus-n6lfw8": undefined,
"--awsui-style-box-shadow-hover-n6lfw8": undefined,
"--awsui-style-box-shadow-readonly-n6lfw8": undefined,
"--awsui-style-color-default-n6lfw8": undefined,
"--awsui-style-color-disabled-n6lfw8": undefined,
"--awsui-style-color-focus-n6lfw8": undefined,
"--awsui-style-color-hover-n6lfw8": undefined,
"--awsui-style-color-readonly-n6lfw8": undefined,
"--awsui-style-placeholder-color-n6lfw8": undefined,
"--awsui-style-placeholder-font-size-n6lfw8": undefined,
"--awsui-style-placeholder-font-style-n6lfw8": undefined,
"--awsui-style-placeholder-font-weight-n6lfw8": undefined,
"borderRadius": undefined,
"borderWidth": undefined,
"fontSize": undefined,
Expand All @@ -72,30 +72,30 @@ exports[`getInputStyles handles all possible style configurations 2`] = `

exports[`getInputStyles handles all possible style configurations 3`] = `
{
"--awsui-style-background-default-c5ek4l": "#ffffff",
"--awsui-style-background-disabled-c5ek4l": "#f0f0f0",
"--awsui-style-background-focus-c5ek4l": "#ffffff",
"--awsui-style-background-hover-c5ek4l": "#fafafa",
"--awsui-style-background-readonly-c5ek4l": "#ffffff",
"--awsui-style-border-color-default-c5ek4l": "#cccccc",
"--awsui-style-border-color-disabled-c5ek4l": "#e0e0e0",
"--awsui-style-border-color-focus-c5ek4l": "#0073bb",
"--awsui-style-border-color-hover-c5ek4l": "#999999",
"--awsui-style-border-color-readonly-c5ek4l": "#e0e0e0",
"--awsui-style-box-shadow-default-c5ek4l": "none",
"--awsui-style-box-shadow-disabled-c5ek4l": "none",
"--awsui-style-box-shadow-focus-c5ek4l": "0 0 0 2px #0073bb",
"--awsui-style-box-shadow-hover-c5ek4l": "0 1px 2px rgba(0,0,0,0.1)",
"--awsui-style-box-shadow-readonly-c5ek4l": "none",
"--awsui-style-color-default-c5ek4l": "#000000",
"--awsui-style-color-disabled-c5ek4l": "#999999",
"--awsui-style-color-focus-c5ek4l": "#000000",
"--awsui-style-color-hover-c5ek4l": "#000000",
"--awsui-style-color-readonly-c5ek4l": "#000000",
"--awsui-style-placeholder-color-c5ek4l": "#999999",
"--awsui-style-placeholder-font-size-c5ek4l": "14px",
"--awsui-style-placeholder-font-style-c5ek4l": "italic",
"--awsui-style-placeholder-font-weight-c5ek4l": "400",
"--awsui-style-background-default-n6lfw8": "#ffffff",
"--awsui-style-background-disabled-n6lfw8": "#f0f0f0",
"--awsui-style-background-focus-n6lfw8": "#ffffff",
"--awsui-style-background-hover-n6lfw8": "#fafafa",
"--awsui-style-background-readonly-n6lfw8": "#ffffff",
"--awsui-style-border-color-default-n6lfw8": "#cccccc",
"--awsui-style-border-color-disabled-n6lfw8": "#e0e0e0",
"--awsui-style-border-color-focus-n6lfw8": "#0073bb",
"--awsui-style-border-color-hover-n6lfw8": "#999999",
"--awsui-style-border-color-readonly-n6lfw8": "#e0e0e0",
"--awsui-style-box-shadow-default-n6lfw8": "none",
"--awsui-style-box-shadow-disabled-n6lfw8": "none",
"--awsui-style-box-shadow-focus-n6lfw8": "0 0 0 2px #0073bb",
"--awsui-style-box-shadow-hover-n6lfw8": "0 1px 2px rgba(0,0,0,0.1)",
"--awsui-style-box-shadow-readonly-n6lfw8": "none",
"--awsui-style-color-default-n6lfw8": "#000000",
"--awsui-style-color-disabled-n6lfw8": "#999999",
"--awsui-style-color-focus-n6lfw8": "#000000",
"--awsui-style-color-hover-n6lfw8": "#000000",
"--awsui-style-color-readonly-n6lfw8": "#000000",
"--awsui-style-placeholder-color-n6lfw8": "#999999",
"--awsui-style-placeholder-font-size-n6lfw8": "14px",
"--awsui-style-placeholder-font-style-n6lfw8": "italic",
"--awsui-style-placeholder-font-weight-n6lfw8": "400",
"borderRadius": "4px",
"borderWidth": "1px",
"fontSize": "14px",
Expand Down
21 changes: 21 additions & 0 deletions src/modal/__integ__/modal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,25 @@ test(
})
);

test(
'keeps focused element visible with custom height',
useBrowser(async browser => {
const page = new BasePageObject(browser);
await browser.url('#/light/modal/custom-dimensions?height=400&footer=true');

await page.click('[data-testid="modal-trigger"]');
const modal = createWrapper().findModal();
const footerSelector = modal.findFooter().toSelector();
const inputSelector = '[data-testid="final-input"]';

await page.keys(['Tab', 'Tab']);
await expect(page.isFocused(inputSelector)).resolves.toBe(true);

const inputBox = await page.getBoundingBox(inputSelector);
const footerBox = await page.getBoundingBox(footerSelector);
const inputCenter = inputBox.top + inputBox.height / 2;
expect(inputCenter).toBeLessThan(footerBox.top);
})
);

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
65 changes: 65 additions & 0 deletions src/modal/__tests__/modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import * as React from 'react';
import { act, fireEvent, render } from '@testing-library/react';

import { warnOnce } from '@cloudscape-design/component-toolkit/internal';

import Autosuggest from '../../../lib/components/autosuggest';
import Button from '../../../lib/components/button/index.js';
import ButtonDropdown from '../../../lib/components/button-dropdown';
Expand All @@ -20,6 +22,15 @@ import { PerformanceMetrics } from '../../internal/analytics';
import { KeyCode } from '../../internal/keycode';

import styles from '../../../lib/components/modal/styles.css.js';

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
warnOnce: jest.fn(),
}));

afterEach(() => {
(warnOnce as jest.Mock).mockReset();
});
class ModalInternalWrapper extends ModalWrapper {
findDialog(): ElementWrapper {
return this.findByClassName(styles.dialog)!;
Expand Down Expand Up @@ -117,6 +128,32 @@ describe('Modal component', () => {
expect(wrapper.findDialog().getElement()).toHaveClass(styles[size]);
});
});

it('width overrides size', () => {
const wrapper = renderModal({ size: 'large', width: 500 });
expect(wrapper.findDialog().getElement()).not.toHaveClass(styles.large);
expect(wrapper.findDialog().getElement()).toHaveClass(styles['custom-width']);
});

it('applies custom width class', () => {
const wrapper = renderModal({ width: 600 });
expect(wrapper.findDialog().getElement()).toHaveClass(styles['custom-width']);
});

it('applies custom height class', () => {
const wrapper = renderModal({ height: 400, footer: <div>Footer</div> });
expect(wrapper.findDialog().getElement()).toHaveClass(styles['custom-height']);
expect(wrapper.findFooter()!.getElement()).toHaveClass(styles['custom-height']);
expect(wrapper.findByClassName(styles.container)!.getElement()).toHaveClass(styles['custom-height-container']);
expect(wrapper.findContent().getElement()).toHaveClass(styles['custom-height-content']);
});

it('applies custom height class when footer is absent', () => {
const wrapper = renderModal({ height: 400 });
expect(wrapper.findDialog().getElement()).toHaveClass(styles['custom-height']);
expect(wrapper.findByClassName(styles.container)!.getElement()).toHaveClass(styles['custom-height-container']);
expect(wrapper.findContent().getElement()).toHaveClass(styles['custom-height-content']);
});
});

describe('position property', () => {
Expand Down Expand Up @@ -555,4 +592,32 @@ describe('Modal component', () => {
}, 10);
});
});

describe('custom dimensions warnings', () => {
it('warns when height is too small', () => {
renderModal({ height: 50 });
expect(warnOnce).toHaveBeenCalledWith(
'Modal',
expect.stringMatching(/^Height \(50px\) is too small\. Modal requires at least \d+px for content/)
);
});

it('warns when width is below minimum', () => {
renderModal({ width: 200 });
expect(warnOnce).toHaveBeenCalledWith(
'Modal',
'Width (200px) is below minimum (320px) and will be adjusted to 320px.'
);
});

it('does not warn when dimensions are valid', () => {
renderModal({ width: 500, height: 400 });
expect(warnOnce).not.toHaveBeenCalled();
});

it('does not warn when dimensions are not provided', () => {
renderModal();
expect(warnOnce).not.toHaveBeenCalled();
});
});
});
Loading