Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: add tab-index in select

qishaoxuan56eae05a0fab
diff --git a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/IconInput.tsx b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/IconInput.tsx
index 98bd66e7a3..8873056498 100644
--- a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/IconInput.tsx
+++ b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/IconInput.tsx
@@ -1,4 +1,4 @@
-import React, { type CSSProperties, useState } from 'react';
+import React, { forwardRef, type CSSProperties, useState } from 'react';
import { Input, styled, InputProps } from '@toeverything/components/ui';
import { StyledHighLightWrapper } from '../StyledComponent';
import { IconNames } from '../types';
@@ -29,38 +29,39 @@ export const PendantIcon = ({
);
};
-export const IconInput = ({
- iconName,
- iconStyle,
- color,
- background,
- ...inputProps
-}: IconInputProps) => {
- return (
- <>
- <PendantIcon
- iconName={iconName}
- iconStyle={iconStyle}
- color={color}
- background={background}
- />
- <Input
- style={{
- flexGrow: '1',
- border: 'none',
- }}
- {...inputProps}
- />
- </>
- );
-};
+export const IconInput = forwardRef<HTMLInputElement, IconInputProps>(
+ ({ iconName, iconStyle, color, background, ...inputProps }, ref) => {
+ return (
+ <>
+ <PendantIcon
+ iconName={iconName}
+ iconStyle={iconStyle}
+ color={color}
+ background={background}
+ />
+ <Input
+ ref={ref}
+ style={{
+ flexGrow: '1',
+ }}
+ noBorder
+ {...inputProps}
+ />
+ </>
+ );
+ }
+);
type HighLightIconInputProps = {
startElement?: React.ReactNode;
endElement?: React.ReactNode;
+ tabIndex?: number;
} & IconInputProps;
-export const HighLightIconInput = (props: HighLightIconInputProps) => {
+export const HighLightIconInput = forwardRef<
+ HTMLInputElement,
+ HighLightIconInputProps
+>((props, ref) => {
const {
onFocus,
onBlur,
@@ -74,6 +75,7 @@ export const HighLightIconInput = (props: HighLightIconInputProps) => {
<StyledHighLightWrapper isFocus={focus}>
{startElement}
<IconInput
+ ref={ref}
onFocus={e => {
setFocus(true);
onFocus?.(e);
@@ -87,7 +89,7 @@ export const HighLightIconInput = (props: HighLightIconInputProps) => {
{endElement}
</StyledHighLightWrapper>
);
-};
+});
const StyledIconWrapper = styled('div')`
display: inline-flex;
diff --git a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Select.tsx b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Select.tsx
index 7f29905d8f..6d0d1f26f9 100644
--- a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Select.tsx
+++ b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Select.tsx
@@ -5,7 +5,7 @@ import React, {
KeyboardEvent,
useRef,
} from 'react';
-import { Add, Delete, Close } from '@mui/icons-material';
+import { Add, Close } from '@mui/icons-material';
import { ModifyPanelContentProps } from './types';
import {
MultiSelectProperty,
@@ -38,6 +38,7 @@ type OptionItemType = {
};
onEnter?: (e: KeyboardEvent) => void;
focused?: boolean;
+ tabIndex?: number;
};
type SelectPropsType = {
@@ -138,6 +139,7 @@ export const BasicSelect = ({
onEnter={() => {
insertOption(options[options.length - 1].id);
}}
+ tabIndex={index + 1}
/>
);
})}
@@ -196,6 +198,7 @@ const OptionItem = ({
iconConfig,
onEnter,
focused,
+ tabIndex,
}: OptionItemType) => {
const theme = useTheme();
const inputRef = useRef<HTMLInputElement>();
@@ -204,11 +207,8 @@ const OptionItem = ({
}, [focused]);
return (
<HighLightIconInput
- componentsProps={{
- input: {
- ref: inputRef,
- },
- }}
+ tabIndex={tabIndex}
+ ref={inputRef}
iconName={iconConfig?.name}
color={iconConfig?.color}
background={iconConfig?.background}
diff --git a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Text.tsx b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Text.tsx
index 5772dc2247..4b0b02298b 100644
--- a/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Text.tsx
+++ b/libs/components/editor-core/src/block-pendant/pendant-modify-panel/Text.tsx
@@ -8,7 +8,7 @@ export default ({
initialValue,
iconConfig,
}: ModifyPanelContentProps) => {
- const [text, setText] = useState(initialValue?.value || '');
+ const [text, setText] = useState((initialValue?.value as string) || '');
return (
<HighLightIconInput
iconName={iconConfig?.iconName}
diff --git a/libs/components/ui/src/input/Input.tsx b/libs/components/ui/src/input/Input.tsx
index b80dcbe888..b0628300c8 100644
--- a/libs/components/ui/src/input/Input.tsx
+++ b/libs/components/ui/src/input/Input.tsx
@@ -1,57 +1,62 @@
-import { forwardRef, type ForwardedRef } from 'react';
-/* eslint-disable no-restricted-imports */
-import InputUnstyled, {
- inputUnstyledClasses,
- type InputUnstyledProps,
-} from '@mui/base/InputUnstyled';
+import React, {
+ forwardRef,
+ type ForwardedRef,
+ type InputHTMLAttributes,
+ type CSSProperties,
+} from 'react';
import { styled } from '../styled';
-/**
- * Input is extend by mui InputUnstyled
- *
- * InputUnstyled Demos:
- *
- * - [Input](https://mui.com/base/react-input/)
- *
- * InputUnstyled API:
- *
- * - [InputUnstyled API](https://mui.com/base/api/input-unstyled/)
- *
- * **/
-export type InputProps = InputUnstyledProps;
+export type InputProps = {
+ startAdornment?: React.ReactNode;
+ endAdornment?: React.ReactNode;
+ style?: CSSProperties;
+ noBorder?: boolean;
+} & InputHTMLAttributes<HTMLInputElement>;
-export const Input = forwardRef(function CustomInput(
- props: InputUnstyledProps,
- ref: ForwardedRef<HTMLDivElement>
-) {
- const { components, ...other } = props;
- return (
- <InputUnstyled
- components={{
- Root: StyledInputRoot,
- Input: StyledInputElement,
- ...components,
- }}
- {...other}
- ref={ref}
- />
- );
-});
+export const Input = forwardRef(
+ (props: InputProps, ref: ForwardedRef<HTMLInputElement>) => {
+ // const { getRootProps, getInputProps } = useInput(props);
+ const {
+ style,
+ startAdornment = null,
+ endAdornment = null,
+ onClick,
+ noBorder = false,
+ ...inputProps
+ } = props;
-const StyledInputRoot = styled('div')(({ theme }) => ({
- height: '32px',
- display: 'flex',
- border: `1px solid ${theme.affine.palette.borderColor}`,
- borderRadius: '10px',
- color: `${theme.affine.palette.secondaryText}`,
- padding: '0 12px',
- fontSize: '14px',
- lineHeight: '1.5',
- transition: 'border .1s',
- [`&.${inputUnstyledClasses.focused}`]: {
- borderColor: `${theme.affine.palette.primary}`,
- },
-}));
+ return (
+ <StyledInputRoot
+ noBorder={noBorder}
+ style={style}
+ onClick={onClick}
+ >
+ {startAdornment}
+ <StyledInputElement ref={ref} {...inputProps} />
+ {endAdornment}
+ </StyledInputRoot>
+ );
+ }
+);
+
+const StyledInputRoot = styled('div')<{ noBorder: boolean }>(
+ ({ noBorder, theme }) => ({
+ height: '32px',
+ display: 'flex',
+ border: noBorder
+ ? 'none'
+ : `1px solid ${theme.affine.palette.borderColor}`,
+ borderRadius: '10px',
+ color: `${theme.affine.palette.secondaryText}`,
+ padding: '0 12px',
+ fontSize: '14px',
+ lineHeight: '1.5',
+ transition: 'border .1s',
+ '&:focus-within': {
+ borderColor: `${theme.affine.palette.primary}`,
+ },
+ })
+);
const StyledInputElement = styled('input')(({ theme }) => ({
fontSize: '14px',