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

runfix: TextInput and nth-child tests #13884

Merged
merged 1 commit into from
Oct 18, 2022
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
188 changes: 98 additions & 90 deletions src/script/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

import React, {ForwardRefRenderFunction, useEffect, useRef} from 'react';
import React, {forwardRef, useEffect} from 'react';

import {CheckIcon, COLOR} from '@wireapp/react-ui-kit';

Expand Down Expand Up @@ -50,100 +50,108 @@ export interface UserInputProps {

const SUCCESS_DISMISS_TIMEOUT = 2500;

const TextInputComponent: ForwardRefRenderFunction<HTMLInputElement, UserInputProps> = ({
autoFocus,
disabled,
errorMessage,
isError,
isSuccess,
label,
name,
onCancel,
onChange,
onBlur,
onKeyDown,
onSuccessDismissed,
placeholder,
value,
uieName,
errorUieName,
inputWrapperRef,
setIsEditing,
}: UserInputProps) => {
const isFilled = Boolean(value);
const textInputRef = useRef<HTMLInputElement>(null);
const TextInput = forwardRef<HTMLInputElement, UserInputProps>(
(
{
autoFocus,
disabled,
errorMessage,
isError,
isSuccess,
label,
name,
onCancel,
onChange,
onBlur,
onKeyDown,
onSuccessDismissed,
placeholder,
value,
uieName,
errorUieName,
inputWrapperRef,
setIsEditing,
},
textInputRef,
) => {
const isFilled = Boolean(value);

useEffect(() => {
if (isSuccess && onSuccessDismissed) {
setTimeout(() => {
onSuccessDismissed();
}, SUCCESS_DISMISS_TIMEOUT);
useEffect(() => {
if (isSuccess && onSuccessDismissed) {
setTimeout(() => {
onSuccessDismissed();
}, SUCCESS_DISMISS_TIMEOUT);
}
}, [isSuccess, onSuccessDismissed]);

let changedColor = undefined;
if (isError) {
changedColor = 'var(--text-input-alert) !important';
}
if (isSuccess) {
changedColor = 'var(--text-input-success) !important';
}
}, [isSuccess, onSuccessDismissed]);

let changedColor = undefined;
if (isError) {
changedColor = 'var(--text-input-alert) !important';
}
if (isSuccess) {
changedColor = 'var(--text-input-success) !important';
}
return (
<div css={containerCSS} ref={inputWrapperRef}>
{isError && errorMessage && (
<span className="label" css={errorMessageCSS} data-uie-name={errorUieName}>
{errorMessage}
</span>
)}

{/* eslint jsx-a11y/no-autofocus : "off" */}
<input
autoFocus={autoFocus}
className="text-input"
css={getInputCSS(disabled, changedColor)}
disabled={disabled}
id={name}
name={name}
value={value}
onChange={onChange}
onBlur={onBlur}
onKeyDown={onKeyDown}
placeholder={placeholder}
ref={textInputRef}
data-uie-name={uieName}
/>

return (
<div css={containerCSS} ref={inputWrapperRef}>
{isError && errorMessage && (
<span className="label" css={errorMessageCSS} data-uie-name={errorUieName}>
{errorMessage}
</span>
)}
<label className="label-medium" css={getLabelCSS(changedColor)} htmlFor={name}>
{label}
</label>

{/* eslint jsx-a11y/no-autofocus : "off" */}
<input
autoFocus={autoFocus}
className="text-input"
css={getInputCSS(disabled, changedColor)}
disabled={disabled}
id={name}
name={name}
value={value}
onChange={onChange}
onBlur={onBlur}
onKeyDown={onKeyDown}
placeholder={placeholder}
ref={textInputRef}
data-uie-name={uieName}
/>
<label className="label-medium" css={getLabelCSS(changedColor)} htmlFor={name}>
{label}
</label>
{isFilled && !isSuccess && !isError && (
<button
type="button"
css={cancelButtonCSS}
onClick={() => {
onCancel();
textInputRef.current?.focus();
}}
aria-label={t('accessibility.userProfileDeleteEntry')}
onKeyDown={(event: React.KeyboardEvent<HTMLButtonElement>): void => {
if (event.shiftKey && isTabKey(event)) {
// shift+tab from clear button should focus on the input field
setIsEditing?.(true);
} else if (isTabKey(event)) {
// tab from clear button should close the editable field
setIsEditing?.(false);
}
}}
>
<Icon.Close css={{fill: 'var(--text-input-background)', height: 8, width: 8}} />
</button>
)}
{isSuccess && !isError && <CheckIcon css={getIconCSS(changedColor)} color={COLOR.TEXT} />}
{isError && <Icon.ExclamationMark css={getIconCSS(changedColor)} color={COLOR.TEXT} />}
</div>
);
};
{isFilled && !isSuccess && !isError && (
<button
type="button"
css={cancelButtonCSS}
onClick={() => {
onCancel();
if (textInputRef && 'current' in textInputRef) {
textInputRef.current?.focus();
}
}}
aria-label={t('accessibility.userProfileDeleteEntry')}
onKeyDown={(event: React.KeyboardEvent<HTMLButtonElement>): void => {
if (event.shiftKey && isTabKey(event)) {
// shift+tab from clear button should focus on the input field
setIsEditing?.(true);
} else if (isTabKey(event)) {
// tab from clear button should close the editable field
setIsEditing?.(false);
}
}}
>
<Icon.Close css={{fill: 'var(--text-input-background)', height: 8, width: 8}} />
</button>
)}
{isSuccess && !isError && <CheckIcon css={getIconCSS(changedColor)} color={COLOR.TEXT} />}
{isError && <Icon.ExclamationMark css={getIconCSS(changedColor)} color={COLOR.TEXT} />}
</div>
);
},
);

const TextInput = React.forwardRef(TextInputComponent);
TextInput.displayName = 'TextInput';

export {TextInput};
10 changes: 5 additions & 5 deletions src/script/page/AccentColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ const AccentColorPicker: React.FunctionComponent<AccentColorPickerProps> = ({use
data-uie-name="do-set-accent-color"
data-uie-value={id}
css={{
'& + label > span:first-child': {
'& + label > span:first-of-type': {
color: color,
cursor: 'pointer',
display: 'inline-block',
position: 'relative',
},
'& + label > span:first-child::after': {
'& + label > span:first-of-type::after': {
...CSS_SQUARE(10),
background: 'currentColor',
transform: 'translate(-50%, -50%)',
},
'& + label > span:first-child::before': {
'& + label > span:first-of-type::before': {
...CSS_SQUARE(16),
transform: 'translate(-50%, -50%)',
},
'& + label > span:first-child::before, & + label > span:first-child::after': {
'& + label > span:first-of-type::before, & + label > span:first-of-type::after': {
borderRadius: '50%',
content: '""',
display: 'inline-block',
position: 'absolute',
transition: 'all 0.15s ease-out',
},
'&:checked + label > span:first-child::before': {
'&:checked + label > span:first-of-type::before': {
border: '1px solid currentColor',
},
'&:focus-visible + label': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const AccountInput: FC<AccountInputProps> = ({
valueUie,
...rest
}) => {
const inputWrapperRef = useRef<HTMLDivElement>(null);
const inputWrapperRef = useRef<HTMLInputElement | null>(null);

const [input, setInput] = useState<string>('');
const [isEditing, setIsEditing] = useState(false);
Expand Down Expand Up @@ -187,7 +187,7 @@ const AccountInput: FC<AccountInputProps> = ({
label={label}
name={valueUie ? valueUie : fieldName}
value={input}
inputWrapperRef={inputWrapperRef}
ref={inputWrapperRef}
onChange={({target}) => updateInput(target.value)}
onCancel={() => {
updateInput('');
Expand Down