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

ui-core, input : fix focus input by using tab keyboard #35

Merged
merged 1 commit into from
Apr 18, 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
20 changes: 2 additions & 18 deletions ui-core/src/components/inputs/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import React from 'react';
import cx from 'classnames';

import useKeyPress from './hooks/useKeyPress';
import FieldWrapper, { FieldWrapperProps } from './FieldWrapper';

type InputAffixProps = {
Expand Down Expand Up @@ -67,19 +66,10 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
statusWithMessage,
inputWrapperClassname,
small = false,
onBlur,
...rest
},
ref
) => {
const [focusViaKeyboard, setFocusViaKeyboard] = useState(false);
useKeyPress('Tab', async () => setFocusViaKeyboard(true));

const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
setFocusViaKeyboard(false);
onBlur?.(e);
};

return (
<FieldWrapper
id={id}
Expand All @@ -90,12 +80,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
required={required}
small={small}
>
<div
className={cx('input-wrapper', inputWrapperClassname, {
focused: focusViaKeyboard,
small,
})}
>
<div className={cx('input-wrapper', inputWrapperClassname, { small })}>
{leadingContent && (
<InputAffix
value={leadingContent}
Expand All @@ -116,7 +101,6 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
type={type}
disabled={disabled}
readOnly={readOnly}
onBlur={handleBlur}
{...rest}
/>
{trailingContent && (
Expand Down
19 changes: 0 additions & 19 deletions ui-core/src/components/inputs/hooks/useKeyPress.tsx

This file was deleted.

1 change: 1 addition & 0 deletions ui-core/src/stories/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const meta: Meta<typeof Input> = {
small: false,
disabled: false,
readOnly: false,
onChange: () => {},
},
title: 'Input',
tags: ['autodocs'],
Expand Down
2 changes: 1 addition & 1 deletion ui-core/src/styles/inputs/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
margin-left: -0.125rem;
width: max-content;

&.focused {
&:has(:focus-visible) {
box-shadow: 0 0 0 0.063rem rgba(37, 106, 250, 1) inset;
}

Expand Down
Loading