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
65 changes: 65 additions & 0 deletions pages/modal/custom-dimensions.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import { Button, 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);

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>
</SpaceBetween>
}
>
<Button data-testid="modal-trigger" onClick={() => setVisible(true)}>
Show modal
</Button>
<ScreenshotArea>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: actually the ScreenshotArea in these pages does nothing, because the modal is positioned visually outside of it. For this reason we need to use captureViewport in the modal visual regression tests and not captureScreenshotArea.

<Modal
header="Custom dimensions modal"
visible={visible}
onDismiss={() => setVisible(false)}
width={urlParams.width ? Number(urlParams.width) : undefined}
height={urlParams.height ? Number(urlParams.height) : undefined}
footer={
<span style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button variant="primary">OK</Button>
</span>
}
>
{Array(100)
.fill(0)
.map((value, index) => (
<div key={index}>
<span>Text content {index}</span>
</div>
))}
<input data-testid="final-input" />
</Modal>
</ScreenshotArea>
</SimplePage>
);
}
43 changes: 43 additions & 0 deletions pages/modal/custom-height-no-footer.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import { Button, Modal } from '~components';

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

function getUrlParams() {
const hashParts = window.location.hash.split('?');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still using the custom URL parameters logic here instead of the existing context hooks :)

Actually could this page be instead implemented as an extra parameter in the other dev page (custom-dimensions.page.tsx), which adds or removes the footer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Done

const params = new URLSearchParams(hashParts[1] || '');
return {
height: params.get('height') ? Number(params.get('height')) : undefined,
};
}

export default function () {
const [visible, setVisible] = useState(false);
const { height } = getUrlParams();

return (
<SimplePage title="Modal with custom height and no footer">
<Button data-testid="modal-trigger" onClick={() => setVisible(true)}>
Show modal
</Button>
<ScreenshotArea>
<Modal
header="Custom height modal without footer"
visible={visible}
onDismiss={() => setVisible(false)}
height={height}
>
{Array(100)
.fill(0)
.map((value, index) => (
<div key={index}>Line {index + 1}: Content</div>
))}
</Modal>
</ScreenshotArea>
</SimplePage>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17503,6 +17503,14 @@ 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.
The minimum height is header height + footer height + 60px content height (to ensure content is accessible).",
"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 +17597,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');

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));
Loading