Skip to content

Commit

Permalink
URLInput: Replace input with InputControl (#65158)
Browse files Browse the repository at this point in the history
* replace input with InputControl

* change the code so that the suffix prop remains undefined if not assigned any component

* Update packages/block-editor/src/components/link-control/index.js

skips passing a prop when suffix isn't needed.

Co-authored-by: Marco Ciampini <[email protected]>

* Update index.js

* minor changes, removed unnecessary comments

* retrigger checks

* added the newlines back for better readability

* Made LinkControl and Social Icons Consistent, fixed the auto-fill highlight issue and finally cleaned up the CSS which was irrelevant after replacing input tag with InputControl

* Lint Issues Fix

* More CSS cleanup plus misc cleanup

* CSS cleanup

---------

Co-authored-by: Marco Ciampini <[email protected]>
Co-authored-by: rahulharpal1603 <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
7 people committed Sep 18, 2024
1 parent 4e7e9f7 commit 48079e9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 73 deletions.
33 changes: 19 additions & 14 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Notice,
TextControl,
__experimentalHStack as HStack,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useRef, useState, useEffect } from '@wordpress/element';
Expand Down Expand Up @@ -383,7 +384,7 @@ function LinkControl( {
value={ internalControlValue?.title }
onChange={ setInternalTextInputValue }
onKeyDown={ handleSubmitWithEnter }
size="__unstable-large"
__next40pxDefaultSize
/>
) }
<LinkControlSearchInput
Expand All @@ -404,20 +405,24 @@ function LinkControl( {
createSuggestionButtonText
}
hideLabelFromVision={ ! showTextControl }
suffix={
showActions ? undefined : (
<InputControlSuffixWrapper variant="control">
<Button
onClick={
isDisabled ? noop : handleSubmit
}
label={ __( 'Submit' ) }
icon={ keyboardReturn }
className="block-editor-link-control__search-submit"
aria-disabled={ isDisabled }
size="small"
/>
</InputControlSuffixWrapper>
)
}
props
/>
{ ! showActions && (
<div className="block-editor-link-control__search-enter">
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
onClick={ isDisabled ? noop : handleSubmit }
label={ __( 'Submit' ) }
icon={ keyboardReturn }
className="block-editor-link-control__search-submit"
aria-disabled={ isDisabled }
/>
</div>
) }
</div>
{ errorMessage && (
<Notice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const LinkControlSearchInput = forwardRef(
withURLSuggestion = true,
createSuggestionButtonText,
hideLabelFromVision = false,
suffix,
},
ref
) => {
Expand Down Expand Up @@ -147,6 +148,7 @@ const LinkControlSearchInput = forwardRef(
}
} }
ref={ ref }
suffix={ suffix }
/>
{ children }
</div>
Expand Down
22 changes: 0 additions & 22 deletions packages/block-editor/src/components/link-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,12 @@ $block-editor-link-control-number-of-actions: 1;
color: $gray-900;
}

input[type="text"],
// Specificity overide of URLInput defaults.
&.block-editor-url-input input[type="text"].block-editor-url-input__input {
@include input-control;
display: block;
border: $border-width solid $gray-600;
height: $button-size-next-default-40px; // components do not properly support unstable-large yet.
margin: 0;
padding: $grid-unit-10 $button-size-next-default-40px $grid-unit-10 $grid-unit-20;
position: relative;
width: 100%;

.has-actions & {
padding-right: $grid-unit-20;
}
}
}

.block-editor-link-control__search-error {
margin: -$grid-unit-20 * 0.5 $grid-unit-20 $grid-unit-20; // negative margin to bring the error a bit closer to the button
}

.block-editor-link-control__search-enter {
position: absolute;
right: 19px; // specific to place the button properly.
top: 3px;
}

.block-editor-link-control__search-actions {
padding: $grid-unit-10 $grid-unit-20 $grid-unit-20;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';
import {
BaseControl,
Button,
__experimentalInputControl as InputControl,
Spinner,
withSpokenMessages,
Popover,
Expand Down Expand Up @@ -234,8 +235,8 @@ class URLInput extends Component {
this.suggestionsRequest = request;
}

onChange( event ) {
this.props.onChange( event.target.value );
onChange( newValue ) {
this.props.onChange( newValue );
}

onFocus() {
Expand Down Expand Up @@ -448,7 +449,6 @@ class URLInput extends Component {
id: inputId,
value,
required: true,
className: 'block-editor-url-input__input',
type: 'text',
onChange: this.onChange,
onFocus: this.onFocus,
Expand All @@ -464,6 +464,7 @@ class URLInput extends Component {
? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`
: undefined,
ref: this.inputRef,
suffix: this.props.suffix,
};

if ( renderControl ) {
Expand All @@ -472,7 +473,7 @@ class URLInput extends Component {

return (
<BaseControl __nextHasNoMarginBottom { ...controlProps }>
<input { ...inputProps } />
<InputControl { ...inputProps } __next40pxDefaultSize />
{ loading && <Spinner /> }
</BaseControl>
);
Expand Down
29 changes: 3 additions & 26 deletions packages/block-editor/src/components/url-input/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@ $input-size: 300px;
position: relative;
padding: 1px;

input[type="text"] {
width: 100%;
@include break-small() {
width: $input-size;
}
padding: $input-padding;
margin-left: 0;
margin-right: 0;

/* Fonts smaller than 16px causes mobile safari to zoom. */
font-size: $mobile-text-min-font-size;
@include break-small {
font-size: $default-font-size;
}

&::-ms-clear {
display: none;
}
@include break-small() {
min-width: $input-size;
width: auto;
}

&.is-full-width {
width: 100%;

.block-editor-url-input__input[type="text"] {
width: 100%;
}

&__suggestions {
width: 100%;
}
Expand All @@ -49,10 +30,6 @@ $input-size: 300px;
}
}

.block-editor-url-input__input[type="text"] {
@include input-control;
}

// Suggestions
.block-editor-url-input__suggestions {
max-height: 200px;
Expand Down
18 changes: 11 additions & 7 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
PanelBody,
PanelRow,
TextControl,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { keyboardReturn } from '@wordpress/icons';
Expand Down Expand Up @@ -78,15 +79,18 @@ const SocialLinkURLPopover = ( {
}
removeBlock( clientId );
} }
suffix={
<InputControlSuffixWrapper variant="control">
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
size="small"
/>
</InputControlSuffixWrapper>
}
/>
</div>
<Button
// TODO: Switch to `true` (40px size) if possible.
__next40pxDefaultSize={ false }
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
);
Expand Down

0 comments on commit 48079e9

Please sign in to comment.