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

MediaPlaceholder: Use InputControl in URL popover #65656

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
.block-editor-media-placeholder__url-input-form {
display: flex;

// Selector requires a lot of specificity to override base styles.
input[type="url"].block-editor-media-placeholder__url-input-field {
Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly, these styles were not applying to the input as intended because it didn't have type="url".

To minimize the risk of unintended consequences for the scope of this PR, I didn't add a type="url" to the InputControl. Let me know if you disagree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me — it could be a change to consider, but not in the scope of this PR

Copy link
Member

Choose a reason for hiding this comment

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

I arrived at this PR from Automattic/wp-calypso#97328 - do folks know why these styles aren't appearing in the site editor?

Post editor

Image

Site editor

Image

Copy link
Contributor

Choose a reason for hiding this comment

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

@ramonjd In gutenberg, on latest trunk, the URL popover works fine for me. Is the screenshot that you posted from Gutenberg, or from the Calypso project?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the reply @ciampo

It was fixed recently in #68501

width: 100%;
min-width: 200px;

@include break-small() {
width: 300px;
}

flex-grow: 1;
border: none;
border-radius: 0;
margin: 2px;
min-width: 260px;
Copy link
Member Author

Choose a reason for hiding this comment

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

The widths don't seem to be particularly intentional to begin with, so just using my best judgement here.


@include break-small() {
width: 300px;
}
}

.block-editor-media-placeholder__url-input-submit-button {
flex-shrink: 1;
}

.block-editor-media-placeholder__cancel-button.is-link {
margin: 1em;
display: block;
Expand Down
34 changes: 17 additions & 17 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
FormFileUpload,
Placeholder,
DropZone,
__experimentalInputControl as InputControl,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
withFilters,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -42,21 +44,23 @@ const InsertFromURLPopover = ( {
className="block-editor-media-placeholder__url-input-form"
onSubmit={ onSubmit }
>
<input
className="block-editor-media-placeholder__url-input-field"
type="text"
aria-label={ __( 'URL' ) }
<InputControl
__next40pxDefaultSize
label={ __( 'URL' ) }
hideLabelFromVision
placeholder={ __( 'Paste or type URL' ) }
onChange={ onChange }
value={ src }
/>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className="block-editor-media-placeholder__url-input-submit-button"
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
suffix={
<InputControlSuffixWrapper variant="control">
<Button
size="small"
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</InputControlSuffixWrapper>
}
/>
</form>
</URLPopover>
Expand Down Expand Up @@ -167,10 +171,6 @@ export function MediaPlaceholder( {
);
};

const onChangeSrc = ( event ) => {
setSrc( event.target.value );
};

const onFilesUpload = ( files ) => {
if (
! handleUpload ||
Expand Down Expand Up @@ -407,7 +407,7 @@ export function MediaPlaceholder( {
onSelectURL && (
<URLSelectionUI
src={ src }
onChangeSrc={ onChangeSrc }
onChangeSrc={ setSrc }
onSelectURL={ onSelectURL }
/>
)
Expand Down
Loading