Skip to content

Commit

Permalink
InputBase: Add isBorderless prop (#58750)
Browse files Browse the repository at this point in the history
* InputBase: Add `isBorderless` prop

* Omit from public InputControl props

* Update changelog

* Update snapshots

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 8227f64 commit 87c5697
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- `Composite`: Removing Reakit `Composite` implementation ([#58620](https://github.com/WordPress/gutenberg/pull/58620)).
- Removing Reakit as a dependency of the components package ([#58631](https://github.com/WordPress/gutenberg/pull/58631)).
- `CustomSelect`: add unit tests ([#58583](https://github.com/WordPress/gutenberg/pull/58583)).
- `InputBase`: Add `isBorderless` prop ([#58750](https://github.com/WordPress/gutenberg/pull/58750)).

## 25.16.0 (2024-01-24)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ exports[`DimensionControl rendering renders with custom sizes 1`] = `
class="components-base-control__field emotion-2 emotion-3"
>
<div
class="components-flex components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
class="components-flex components-input-base components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
data-wp-c16t="true"
data-wp-component="Flex"
data-wp-component="InputBase"
>
<div
class="components-flex-item emotion-7 emotion-8 emotion-6"
Expand Down Expand Up @@ -459,9 +459,9 @@ exports[`DimensionControl rendering renders with defaults 1`] = `
class="components-base-control__field emotion-2 emotion-3"
>
<div
class="components-flex components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
class="components-flex components-input-base components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
data-wp-c16t="true"
data-wp-component="Flex"
data-wp-component="InputBase"
>
<div
class="components-flex-item emotion-7 emotion-8 emotion-6"
Expand Down Expand Up @@ -740,9 +740,9 @@ exports[`DimensionControl rendering renders with icon and custom icon label 1`]
class="components-base-control__field emotion-2 emotion-3"
>
<div
class="components-flex components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
class="components-flex components-input-base components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
data-wp-c16t="true"
data-wp-component="Flex"
data-wp-component="InputBase"
>
<div
class="components-flex-item emotion-7 emotion-8 emotion-6"
Expand Down Expand Up @@ -1033,9 +1033,9 @@ exports[`DimensionControl rendering renders with icon and default icon label 1`]
class="components-base-control__field emotion-2 emotion-3"
>
<div
class="components-flex components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
class="components-flex components-input-base components-select-control block-editor-dimension-control emotion-4 emotion-5 emotion-6"
data-wp-c16t="true"
data-wp-component="Flex"
data-wp-component="InputBase"
>
<div
class="components-flex-item emotion-7 emotion-8 emotion-6"
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/input-control/backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import { memo } from '@wordpress/element';
*/
import { BackdropUI } from './styles/input-control-styles';

function Backdrop( { disabled = false, isFocused = false } ) {
function Backdrop( {
disabled = false,
isBorderless = false,
isFocused = false,
} ) {
return (
<BackdropUI
aria-hidden="true"
className="components-input-control__backdrop"
disabled={ disabled }
isBorderless={ isBorderless }
isFocused={ isFocused }
/>
);
Expand Down
19 changes: 14 additions & 5 deletions packages/components/src/input-control/input-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ForwardedRef } from 'react';
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { forwardRef, useMemo } from '@wordpress/element';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -23,7 +23,11 @@ import {
} from './styles/input-control-styles';
import type { InputBaseProps, LabelPosition } from './types';
import type { WordPressComponentProps } from '../context';
import { ContextSystemProvider } from '../context';
import {
ContextSystemProvider,
contextConnect,
useContextSystem,
} from '../context';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';

function useUniqueId( idProp?: string ) {
Expand Down Expand Up @@ -73,14 +77,15 @@ export function InputBase(
hideLabelFromVision = false,
labelPosition,
id: idProp,
isBorderless = false,
isFocused = false,
label,
prefix,
size = 'default',
suffix,
...restProps
} = useDeprecated36pxDefaultSizeProp(
props,
useContextSystem( props, 'InputBase' ),
'wp.components.InputBase',
'6.4'
);
Expand Down Expand Up @@ -138,10 +143,14 @@ export function InputBase(
</Suffix>
) }
</ContextSystemProvider>
<Backdrop disabled={ disabled } isFocused={ isFocused } />
<Backdrop
disabled={ disabled }
isBorderless={ isBorderless }
isFocused={ isFocused }
/>
</Container>
</Root>
);
}

export default forwardRef( InputBase );
export default contextConnect( InputBase, 'InputBase' );
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const Input = styled.input< InputProps >`
box-sizing: border-box;
border: none;
box-shadow: none !important;
color: ${ COLORS.gray[ 900 ] };
color: ${ COLORS.theme.foreground };
display: block;
font-family: inherit;
margin: 0;
Expand Down Expand Up @@ -263,28 +263,31 @@ export const LabelWrapper = styled( FlexItem )`

type BackdropProps = {
disabled?: boolean;
isBorderless?: boolean;
isFocused?: boolean;
};

const backdropFocusedStyles = ( {
disabled,
isBorderless,
isFocused,
}: BackdropProps ): SerializedStyles => {
let borderColor = isFocused ? COLORS.ui.borderFocus : COLORS.ui.border;
let borderColor = isBorderless ? 'transparent' : COLORS.ui.border;

let boxShadow;
let outline;
let outlineOffset;

if ( isFocused ) {
borderColor = COLORS.ui.borderFocus;
boxShadow = CONFIG.controlBoxShadowFocus;
// Windows High Contrast mode will show this outline, but not the box-shadow.
outline = `2px solid transparent`;
outlineOffset = `-2px`;
}

if ( disabled ) {
borderColor = COLORS.ui.borderDisabled;
borderColor = isBorderless ? 'transparent' : COLORS.ui.borderDisabled;
}

return css( {
Expand Down
11 changes: 10 additions & 1 deletion packages/components/src/input-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,19 @@ export interface InputBaseProps extends BaseProps, FlexProps {
* If this property is added, a label will be generated using label property as the content.
*/
label?: ReactNode;
/**
* Whether to hide the border when not focused.
*
* @default false
*/
isBorderless?: boolean;
}

export interface InputControlProps
extends Omit< InputBaseProps, 'children' | 'isFocused' | keyof FlexProps >,
extends Omit<
InputBaseProps,
'children' | 'isBorderless' | 'isFocused' | keyof FlexProps
>,
Pick< BaseControlProps, 'help' >,
/**
* The `prefix` prop in `WordPressComponentProps< InputFieldProps, 'input', false >` comes from the
Expand Down

0 comments on commit 87c5697

Please sign in to comment.