Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal: add size prop to support a selection of preset modal sizes #54471

Merged
merged 18 commits into from
Sep 29, 2023

Conversation

chad1008
Copy link
Contributor

@chad1008 chad1008 commented Sep 14, 2023

What?

Implements a new prop for Modal that constrains the content width to one of a selection of preset sizes.

Why?

Consumers were finding they often needed to manually set a max width on the child elements they provided to Modal to prevent them from pushing Modal's size to the full with of the viewport.

How?

The optional new prop accepts values of small, medium, and large. If provided, the width of the Modal's contents will be limited to 300px, 600px, or 900px, respectively. (Note: these are just my initial values, and can most certainly be changed as needed when this PR is reviewed).

The value provided to the prop is used to add an additional class name to the relevant DOM element, but this class is only added if isFullscreen is false, so full screen modals will not be affected. Further, the styles implementing this change are limited to larger screens, so the automatically full screen Modal rendering on mobile devices should not be affected either.


dropping a ping for some folks who may want to weigh in on any design considerations for this one: @jordesign @koster @SaxonF

Testing Instructions

npm run storybook:dev

  • Open Modal's new With contentWidth: small story and test the contentWidth control.
  • Confirm that both isFullScreen behaves as expected with the new prop applied
  • Confirm smaller viewports still render the modal in full screen, regardless of the new prop's value

Testing Instructions for Keyboard

n/a

@github-actions
Copy link

github-actions bot commented Sep 14, 2023

Size Change: +156 B (0%)

Total Size: 1.62 MB

Filename Size Change
build/components/index.min.js 248 kB +40 B (0%)
build/components/style-rtl.css 11.9 kB +59 B (0%)
build/components/style.css 11.9 kB +57 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 964 B
build/annotations/index.min.js 2.71 kB
build/api-fetch/index.min.js 2.29 kB
build/autop/index.min.js 2.11 kB
build/blob/index.min.js 461 B
build/block-directory/index.min.js 7.07 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/content-rtl.css 4.28 kB
build/block-editor/content.css 4.27 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
build/block-editor/index.min.js 218 kB
build/block-editor/style-rtl.css 15.6 kB
build/block-editor/style.css 15.6 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 138 B
build/block-library/blocks/audio/theme.css 138 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 587 B
build/block-library/blocks/button/editor.css 587 B
build/block-library/blocks/button/style-rtl.css 633 B
build/block-library/blocks/button/style.css 632 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.7 kB
build/block-library/blocks/cover/style.css 1.69 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 138 B
build/block-library/blocks/embed/theme.css 138 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 311 B
build/block-library/blocks/file/style.css 312 B
build/block-library/blocks/file/view.min.js 321 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 957 B
build/block-library/blocks/gallery/editor.css 962 B
build/block-library/blocks/gallery/style-rtl.css 1.55 kB
build/block-library/blocks/gallery/style.css 1.55 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 189 B
build/block-library/blocks/heading/style.css 189 B
build/block-library/blocks/html/editor-rtl.css 340 B
build/block-library/blocks/html/editor.css 341 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.4 kB
build/block-library/blocks/image/style.css 1.39 kB
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/image/view.min.js 1.83 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 505 B
build/block-library/blocks/media-text/style.css 503 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 671 B
build/block-library/blocks/navigation-link/editor.css 672 B
build/block-library/blocks/navigation-link/style-rtl.css 103 B
build/block-library/blocks/navigation-link/style.css 103 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view.min.js 1.01 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 322 B
build/block-library/blocks/post-featured-image/style.css 322 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 314 B
build/block-library/blocks/post-template/style.css 314 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 168 B
build/block-library/blocks/pullquote/theme.css 168 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/style-rtl.css 375 B
build/block-library/blocks/query/style.css 372 B
build/block-library/blocks/query/view.min.js 609 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 613 B
build/block-library/blocks/search/style.css 613 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 471 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 329 B
build/block-library/blocks/shortcode/editor.css 329 B
build/block-library/blocks/site-logo/editor-rtl.css 760 B
build/block-library/blocks/site-logo/editor.css 760 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 682 B
build/block-library/blocks/social-links/editor.css 681 B
build/block-library/blocks/social-links/style-rtl.css 1.45 kB
build/block-library/blocks/social-links/style.css 1.45 kB
build/block-library/blocks/spacer/editor-rtl.css 359 B
build/block-library/blocks/spacer/editor.css 359 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 432 B
build/block-library/blocks/table/editor.css 432 B
build/block-library/blocks/table/style-rtl.css 646 B
build/block-library/blocks/table/style.css 645 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 191 B
build/block-library/blocks/video/style.css 191 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.11 kB
build/block-library/common.css 1.11 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.2 kB
build/block-library/editor.css 12.2 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 207 kB
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/style-rtl.css 14 kB
build/block-library/style.css 14 kB
build/block-library/theme-rtl.css 700 B
build/block-library/theme.css 705 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.5 kB
build/commands/index.min.js 15.5 kB
build/commands/style-rtl.css 947 B
build/commands/style.css 942 B
build/compose/index.min.js 12.7 kB
build/core-commands/index.min.js 2.72 kB
build/core-data/index.min.js 70.5 kB
build/customize-widgets/index.min.js 12 kB
build/customize-widgets/style-rtl.css 1.51 kB
build/customize-widgets/style.css 1.5 kB
build/data-controls/index.min.js 651 B
build/data/index.min.js 8.78 kB
build/date/index.min.js 17.9 kB
build/deprecated/index.min.js 462 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.68 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/index.min.js 35.7 kB
build/edit-post/style-rtl.css 7.92 kB
build/edit-post/style.css 7.91 kB
build/edit-site/index.min.js 185 kB
build/edit-site/style-rtl.css 14 kB
build/edit-site/style.css 14 kB
build/edit-widgets/index.min.js 17 kB
build/edit-widgets/style-rtl.css 4.84 kB
build/edit-widgets/style.css 4.84 kB
build/editor/index.min.js 45.9 kB
build/editor/style-rtl.css 3.58 kB
build/editor/style.css 3.58 kB
build/element/index.min.js 4.87 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 7.79 kB
build/format-library/style-rtl.css 577 B
build/format-library/style.css 577 B
build/hooks/index.min.js 1.57 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.61 kB
build/interactivity/index.min.js 11.4 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.76 kB
build/keycodes/index.min.js 1.9 kB
build/list-reusable-blocks/index.min.js 2.21 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 964 B
build/nux/index.min.js 2.01 kB
build/nux/style-rtl.css 775 B
build/nux/style.css 771 B
build/patterns/index.min.js 3.57 kB
build/patterns/style-rtl.css 325 B
build/patterns/style.css 325 B
build/plugins/index.min.js 1.81 kB
build/preferences-persistence/index.min.js 1.85 kB
build/preferences/index.min.js 1.26 kB
build/primitives/index.min.js 994 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 972 B
build/react-i18n/index.min.js 631 B
build/react-refresh-entry/index.min.js 9.46 kB
build/react-refresh-runtime/index.min.js 6.78 kB
build/redux-routine/index.min.js 2.71 kB
build/reusable-blocks/index.min.js 2.73 kB
build/reusable-blocks/style-rtl.css 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 10.2 kB
build/router/index.min.js 1.79 kB
build/server-side-render/index.min.js 1.96 kB
build/shortcode/index.min.js 1.4 kB
build/style-engine/index.min.js 1.98 kB
build/token-list/index.min.js 587 B
build/url/index.min.js 3.84 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 967 B
build/warning/index.min.js 259 B
build/widgets/index.min.js 7.18 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.03 kB

compressed-size-action

@chad1008 chad1008 marked this pull request as ready for review September 15, 2023 04:14
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

It would be good to get some input from @WordPress/gutenberg-design :

  • is the proposed approach compatible with your needs (ie. setting a max width) ?
  • do you have any advice on the number of set widths (for now we added 3 options, small / medium / large) and the corresponding px widths (300/600/900) ?
  • do you have any advice on what is the expected behaviour of the component:
    • when the viewport's width is lower than the selected max width
    • when the isFullScreen prop is true (which makes the modal go full screen on mobile screens)

@jameskoster
Copy link
Contributor

is the proposed approach compatible with your needs (ie. setting a max width) ?

That seems reasonable to me, we might want to consider a min-width too.

do you have any advice on the number of set widths

Perhaps we'll want to align these with general content widths that emerge out of #53322. For now using values from the 4px baseline is probably adequate. Maybe:

  • Small – 384px. This can work well for confirmDialogs, renames, and single-action modals
  • Medium – 512px. Welcome guides, Keyboard shortcuts.
  • Large – 832px. Template creation, editor preferences.
  • Fill – stretched. Media library, pattern explorer, etc.

when the viewport's width is lower than the selected max width

I may be missing something but I don't think I'd expect any special behavior in this case? The modal would just fill the width (accounting any margin or padding on the container).

We might consider positioning modals towards the bottom of the viewport on mobile widths, similar to sheets on mobile OS's e.g.:

Mobile

I acknowledge that's probably an optimisation to explore separately.

when the isFullScreen prop is true (which makes the modal go full screen on mobile screens)

This doesn't only affect mobile, it also stretches the modal to fill the viewport on desktop, right? Should this be deprecated in favor of a "fill" size? It would be a bit strange imo to allow a small + isFullScreen combo.

@richtabor
Copy link
Member

richtabor commented Sep 18, 2023

Just a note. Is it intentional that command palette width is omitted from this, or is the idea that it conforms to one of these sizes?

It sits at 420px right now. If the latter, 512px seems quite wide for the palette imo. The larger it is, the more it blocks the context of where you are/what you're doing.

CleanShot 2023-09-18 at 16 14 21

@SaxonF
Copy link
Contributor

SaxonF commented Sep 19, 2023

+1 on eventually standardising width values.

One tiny detail. I wonder if shorter sm, md, lg format might be more familiar to folks and slightly more scalable e.g. xs, xl, 2xl etc

@ciampo
Copy link
Contributor

ciampo commented Sep 19, 2023

@jameskoster

I may be missing something but I don't think I'd expect any special behavior in this case? The modal would just fill the width (accounting any margin or padding on the container).

Sounds good — I was indeed wondering if there should be some margin around the modal to that some portion of the backdrop is always revealed

We might consider positioning modals towards the bottom of the viewport on mobile widths, similar to sheets on mobile OS's

FWIW, I've also seen examples where a Modal becomes a "bottom drawer" on mobile screens. But that's a separate conversation.

This doesn't only affect mobile, it also stretches the modal to fill the viewport on desktop, right? Should this be deprecated in favor of a "fill" size? It would be a bit strange imo to allow a small + isFullScreen combo.

I must have gotten confused by the storybook example), where we the arbitrary max-width that we set via inline styles is interfering with full screen styles.

I also agree that a better solution could be to deprecate the isFullScreen prop in favour of one extra option for the new prop that we're adding in this PR 👌


@richtabor

Is it intentional that command palette width is omitted from this, or is the idea that it conforms to one of these sizes?

I'll let the rest of the design team answer this, but let's keep in mind that the aim of this new prop is to give a few presets for the Modal width, but consumers of the component should be able to specify any custom width via standard CSS as always.


@SaxonF

One tiny detail. I wonder if shorter sm, md, lg format might be more familiar to folks and slightly more scalable e.g. xs, xl, 2xl etc

I don't have a strong opinion on this, but we should mention that historically components in this package used the full word when referring to sizing (ie. 'small', 'large' etc.).

@chad1008 chad1008 self-assigned this Sep 22, 2023
@chad1008
Copy link
Contributor Author

Thank you, everyone, for the input! I've pushed some changes to incorporate the above ideas. Summarizing the new bits:

  • removed the max-width from the default story, so it better represents a vanilla Modal and doesn't interfere with the new contentWidth control.
  • added a fill option for the new prop. This will mirror the functionality of the current isFullScreen prop. Note, the isFullScreen prop still works as it always did.
  • added a deprecation warning for isFullScreen - @ciampo, this is the first prop I'm deprecating, please feel free to double check I'm going about it properly 😄
  • updated the small/medium/large widths to the values suggested by @jameskoster (thank for those btw, I like the feel of them much better, and it's good to know there's consistency). I also added a note linking back to that comment for context on where those numbers came from.

@chad1008 chad1008 added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Sep 22, 2023
@jameskoster
Copy link
Contributor

I wonder if medium should be the default instead of a dedicated size in the scale? Ideally consumers are creating modals that are consistent with those in core 99% of the time, and custom sizes are the exception. The current setup might promote custom sizing more than we like?

Comment on lines 160 to 168
&.has-width-small {
max-width: 384px;
}
&.has-width-medium {
max-width: 512px;
}
&.has-width-large {
max-width: 832px;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these values be abstracted into variables? It may be useful for container widths (see #53322).

Copy link
Contributor

Choose a reason for hiding this comment

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

Should these values be abstracted into variables?

If we want these values to be shared across the whole project (not just modal / components), we could for now add the to the base styles package (knowing that they could be later be moved to whatever the centralised place for style variables is going to be)

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

As I reviewed this PR, I had a thought.

I'm not sure that it makes sense to replace isFullScreen with contentWidth="fill". That's because making the modal full screen doesn't only affect the width, but also the height of the component — and therefore using a prop called contentWidth doesn't seem appropriate.

Also, I don't really like the content part either — after all, we're setting the size of the whole modal, not just its contents.

Therefore, I propose two alternatives:

  • we keep the isFullScreen prop around (no deprecation), and we add a new prop (contentWidth, or a better name if we can find one). When the isFullScreen prop is set, the new prop gets ignored.
  • we find a new name for the contentWidth prop (one that doesn't only refer to the width, and that doesn't only refer to the modal contents), so that we can effectively have it replace the isFullScreen prop

What do folks think?

packages/components/src/modal/index.tsx Outdated Show resolved Hide resolved
packages/components/src/modal/README.md Outdated Show resolved Hide resolved
Comment on lines 160 to 168
&.has-width-small {
max-width: 384px;
}
&.has-width-medium {
max-width: 512px;
}
&.has-width-large {
max-width: 832px;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these values be abstracted into variables?

If we want these values to be shared across the whole project (not just modal / components), we could for now add the to the base styles package (knowing that they could be later be moved to whatever the centralised place for style variables is going to be)

packages/components/src/modal/style.scss Outdated Show resolved Hide resolved
packages/components/src/modal/style.scss Outdated Show resolved Hide resolved
@chad1008
Copy link
Contributor Author

Thanks @jameskoster and @ciampo. After those helpful comments I'd propose the following:

  • rename contentWidth to something like modalSize or just size.
  • size="fill" will replace isFullScreen, which will eventually be deprecated.
  • set size="medium" to be the default value.

This way we have only one prop handling the sizing of the modal, and it has a name more accurate name. Thoughts?

@jameskoster
Copy link
Contributor

I think the thing to avoid is contradictory configurations like size=small & isFullScreen, so that seems reasonable to me.

If medium becomes the default, do we still need a medium option, or would it be cleaner to omit that?

@ciampo
Copy link
Contributor

ciampo commented Sep 27, 2023

  • set size="medium" to be the default value.

Setting a preset size as default will potentially visually break existing usages of Modal, since suddenly the modal size would change to the new default value.

The safer approach would be to leave the default value as undefined.

@jameskoster
Copy link
Contributor

That's true, but isn't part of this effort to establish more consistent modal usage? At the moment there is a tendency to apply custom widths to each modal ad hoc, and without a more opinionated default I'd be a little anxious about that continuing.

FWIW I wasn't suggesting automatically setting the size prop, just updating this css:

max-width: calc(100% - #{$grid-unit-20 * 2});

So if a modal is already applying a custom size, it shouldn't be affected. But any new instances would effectively be medium rather than the current ~100% (which isn't very practical).

@ciampo
Copy link
Contributor

ciampo commented Sep 27, 2023

I believe that, in order to ensure ease of composition, each component should only take ownership of its bounding box, ie. it should not set its own size and margins. And therefore, if I were to build this component from scratch, I wouldn't add any width/height in its default state, and grow as its content requires it.

But I understand that the component already currently comes with a set max-width and there is value in ensuring consistency by exposing a size prop.

isn't part of this effort to establish more consistent modal usage? At the moment there is a tendency to apply custom widths to each modal ad hoc, and without a more opinionated default I'd be a little anxious about that continuing.

Having an additional property to pick a preset size from is a convenient way for folks to pick a size without much effort (compared to writing custom styles), and in a way that is consistent across the product.

FWIW I wasn't suggesting automatically setting the size prop, just updating this css:

max-width: calc(100% - #{$grid-unit-20 * 2});

So if a modal is already applying a custom size, it shouldn't be affected. But any new instances would effectively be medium rather than the current ~100% (which isn't very practical).

I see what you mean. While this isn't as disruptive as adding size='medium' as default, it will still definitely introduce some level of disruption. But if you believe that it's worth to trade some disruption in exchange for more consistency (and a better default), then feel free to go ahead with the new proposed max-width.

@chad1008
Copy link
Contributor Author

If medium becomes the default, do we still need a medium option, or would it be cleaner to omit that?

I had the exact same thought, but @ciampo pointed out in a separate convo that setting a default in the CSS will constrain the max-width, but still allow for smaller Modals based on the size of their contents (down to the min-width at least). The actual size="medium" option actually forces that width, regardless of how small the contents are. So they do serve different purposes.

Granted, the current min-width is 350px, only 34px below the proposed default, so that flexibility likely won't come into play too often in practice. 🤔

I've applied a medium default in the CSS for now, but if we decide against it, or if we feel like size='medium' is redundant I'm happy to make those adjustments'.

I've also abstracted the widths to variables in base-styles as suggested previously. Is $modal-width-..., etc., a set of names everyone is happy with? I thought of using $dialog-width-... to avoid being overly specific to Modal, but I was kind of on the fence.

@jameskoster
Copy link
Contributor

jameskoster commented Sep 28, 2023

But if you believe that it's worth to trade some disruption in exchange for more consistency (and a better default), then feel free to go ahead with the new proposed max-width.

It's hard to say without knowing how much disruption will be caused. Maybe we play it safe and leave the current max-width (sorry @chad1008 🙈). Like you said the new prop will hopefully encourage more responsible usage.

I've also abstracted the widths to variables in base-styles as suggested previously. Is $modal-width-..., etc., a set of names everyone is happy with? I thought of using $dialog-width-...

I was thinking more generic than that; $container-width-..., or maybe even just $width-.... @SaxonF had you thought about width variables at all relating to #53322?

@ciampo
Copy link
Contributor

ciampo commented Sep 28, 2023

It's hard to say without knowing how much disruption will be caused. Maybe we play it safe and leave the current max-width (sorry @chad1008 🙈). Like you said the new prop will hopefully encourage more responsible usage.

Alright, so to recap:

  • we leave the current max-width as-is
  • we introduce the new size prop, with a default value of undefined and possible values of 'small' | 'medium' | 'large' | 'fill',
  • the 'fill' option replaces the isFullScreen prop. As follow-up tasks, we should aim at:
    • Replace all usages of isFullScreen with size="fill"
    • Deprecate the isFullScreen prop
  • As another follow-up, we should see if the new size prop can be used instead of the changes introduced in Font Library: fix modal width on mobile viewport #54518

I was thinking more generic than that; $container-width-..., or maybe even just $width-.... @SaxonF had you thought about width variables at all relating to #53322?

I guess this conversation can happen in parallel from the changes in this PR. We can always refactor code internal to Modal since it wouldn't affect the consumers of the component.

@github-actions
Copy link

Flaky tests detected in 14669de.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6356464987
📝 Reported issues:

@chad1008 chad1008 merged commit 83044ca into trunk Sep 29, 2023
51 checks passed
@chad1008 chad1008 deleted the add/modal-content-width branch September 29, 2023 20:38
@github-actions github-actions bot added this to the Gutenberg 16.8 milestone Sep 29, 2023
@ciampo ciampo added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Oct 12, 2023
@mirka mirka changed the title Modal: add contentWidth prop to support a selection of preset modal sizes Modal: add size prop to support a selection of preset modal sizes Feb 26, 2024
@mirka
Copy link
Member

mirka commented Feb 26, 2024

@chad1008 I see Marco added a "Needs Dev Note" label, but I'm not sure what the intent was. I'm guessing it was just to inform consumers of this new size prop. However from this later thread, I was under the impression that we are not quite ready to advertise and encourage wide adoption of these size presets in their current state. Is that correct? Would you agree that we should probably refrain from a Dev Note here?

@chad1008
Copy link
Contributor Author

@mirka Yes, the endgame behavior of the new size prop was kind of up in the air, and while we're using it internally it's probably best that that we don't encourage wider adoption. If a future change adds height constraints to this prop it could negatively impact existing uses we aren't aware of. With that in mind, I'd say holding off on a Dev Note makes sense.

@mirka mirka removed the Needs Dev Note Requires a developer note for a major WordPress release cycle label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants