diff --git a/core/components/atoms/editable/Editable.tsx b/core/components/atoms/editable/Editable.tsx index b89953daab..1db512c9f7 100644 --- a/core/components/atoms/editable/Editable.tsx +++ b/core/components/atoms/editable/Editable.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import classNames from 'classnames'; import { BaseProps, extractBaseProps } from '@/utils/types'; +import { EditableProvider } from '@/utils/EditableContext'; export interface EditableProps extends BaseProps { editing?: boolean; @@ -31,7 +32,7 @@ export const Editable = (props: EditableProps) => { onMouseLeave={() => !editing && onChange('default')} > {/* eslint-enable */} - {children} + {children} ); diff --git a/core/components/molecules/chipInput/ChipInput.tsx b/core/components/molecules/chipInput/ChipInput.tsx index 090ff29c56..b6dc36ff43 100644 --- a/core/components/molecules/chipInput/ChipInput.tsx +++ b/core/components/molecules/chipInput/ChipInput.tsx @@ -3,6 +3,7 @@ import classNames from 'classnames'; import { Chip, Icon } from '@/index'; import { ChipProps } from '@/index.type'; import { BaseProps, extractBaseProps } from '@/utils/types'; +import editableContext from '@/utils/EditableContext'; const keyCodes = { BACKSPACE: 'Backspace', @@ -85,6 +86,7 @@ export const ChipInput = (props: ChipInputProps) => { const inputRef = React.createRef(); const [chips, setChips] = React.useState(value || defaultValue); const [inputValue, setInputValue] = React.useState(''); + const { editable } = React.useContext(editableContext); const baseProps = extractBaseProps(props); @@ -98,7 +100,7 @@ export const ChipInput = (props: ChipInputProps) => { { ChipInput: true, ['ChipInput--disabled']: disabled, - ['ChipInput--withChips']: chips.length > 0, + ['ChipInput--withChips']: chips && chips.length > 0, }, className ); @@ -181,7 +183,7 @@ export const ChipInput = (props: ChipInputProps) => { type={type} disabled={disabled} key={index} - className="my-2 mx-2" + className="my-3 mx-2" onClick={() => onClick && onClick(chip, index)} onClose={() => onChipDeleteHandler(index)} {...rest} @@ -192,33 +194,35 @@ export const ChipInput = (props: ChipInputProps) => { return ( /* TODO(a11y): fix accessibility */ /* eslint-disable */ -
-
- {chips && chips.length > 0 && chipComponents} - - {/* eslint-enable */} +
+
+
+ {chips && chips.length > 0 && chipComponents} + 0 ? '' : placeholder} + disabled={disabled} + value={inputValue} + onBlur={onBlur} + onFocus={onFocus} + onChange={onInputChangeHandler} + onKeyDown={onKeyDownHandler} + /> + {/* eslint-enable */} +
+ {chips.length > 0 && !editable && ( + + )}
- {chips.length > 0 && ( - - )}
); }; diff --git a/core/components/molecules/chipInput/__tests__/__snapshots__/ChipInput.test.tsx.snap b/core/components/molecules/chipInput/__tests__/__snapshots__/ChipInput.test.tsx.snap index 24768843db..80952aaa7a 100644 --- a/core/components/molecules/chipInput/__tests__/__snapshots__/ChipInput.test.tsx.snap +++ b/core/components/molecules/chipInput/__tests__/__snapshots__/ChipInput.test.tsx.snap @@ -6,80 +6,85 @@ exports[`ChipInput component
- - 1020 -
- + 1020 + +
- clear_round - + + clear_round + +
-
-
- - 80 -
- + 80 + +
- clear_round - + + clear_round + +
+
- + + close_round +
- - close_round -
@@ -91,81 +96,86 @@ exports[`ChipInput component
- - 1020 -
- + 1020 + +
- clear_round - + + clear_round + +
-
-
- - 80 -
- + 80 + +
- clear_round - + + clear_round + +
+
- + + close_round +
- - close_round -
diff --git a/core/components/molecules/editableChipInput/EditableChipInput.tsx b/core/components/molecules/editableChipInput/EditableChipInput.tsx index 05fcb3237c..c668deb13f 100644 --- a/core/components/molecules/editableChipInput/EditableChipInput.tsx +++ b/core/components/molecules/editableChipInput/EditableChipInput.tsx @@ -123,7 +123,7 @@ export const EditableChipInput = (props: EditableChipInputProps) => { key={index} name={val} label={val} - className="my-2 mx-2" + className="my-3 mx-2" {...chipObject} onClose={() => onChipDelete(index)} onClick={() => onClick && onClick(val, index)} @@ -151,7 +151,12 @@ export const EditableChipInput = (props: EditableChipInputProps) => { ); } return ( -
+
setShowComponent(true)} + tabIndex={0} //eslint-disable-line jsx-a11y/no-noninteractive-tabindex + > {renderDefaultState()}
); @@ -169,6 +174,7 @@ export const EditableChipInput = (props: EditableChipInputProps) => { icon="clear" className="mr-3" size="tiny" + largeIcon={true} onClick={() => { setDefaultComponent(value); }} @@ -177,6 +183,7 @@ export const EditableChipInput = (props: EditableChipInputProps) => { data-test="DesignSystem-EditableChipInput--SaveButton" icon="check" appearance="primary" + largeIcon={true} size="tiny" disabled={disableSaveAction} onClick={onSaveChanges} diff --git a/core/components/molecules/editableChipInput/__tests__/EditableChipInput.test.tsx b/core/components/molecules/editableChipInput/__tests__/EditableChipInput.test.tsx index 1257f14886..36a82ab254 100644 --- a/core/components/molecules/editableChipInput/__tests__/EditableChipInput.test.tsx +++ b/core/components/molecules/editableChipInput/__tests__/EditableChipInput.test.tsx @@ -137,4 +137,12 @@ describe('EditableChipInput component with action buttons and props: value and c expect(getAllByTestId('DesignSystem-EditableChipInput--Chip')[0].textContent).toMatch('Chip3clear_round'); expect(getAllByTestId('DesignSystem-EditableChipInput--Chip')[1].textContent).toMatch('Chip4clear_round'); }); + + it('does not render close icon', () => { + const { queryByTestId } = render( + + ); + + expect(queryByTestId('DesignSystem-ChipInput--Icon')).not.toBeInTheDocument(); + }); }); diff --git a/core/components/molecules/editableChipInput/__tests__/__snapshots__/EditableChipInput.test.tsx.snap b/core/components/molecules/editableChipInput/__tests__/__snapshots__/EditableChipInput.test.tsx.snap index 6f0fd10e47..f4fe1ab9dc 100644 --- a/core/components/molecules/editableChipInput/__tests__/__snapshots__/EditableChipInput.test.tsx.snap +++ b/core/components/molecules/editableChipInput/__tests__/__snapshots__/EditableChipInput.test.tsx.snap @@ -18,9 +18,10 @@ exports[`EditableChipInput component
@@ -46,7 +47,7 @@ exports[`EditableChipInput component
@@ -96,9 +97,10 @@ exports[`EditableChipInput component
@@ -124,7 +126,7 @@ exports[`EditableChipInput component
diff --git a/core/utils/EditableContext.ts b/core/utils/EditableContext.ts new file mode 100644 index 0000000000..5f4ccb1327 --- /dev/null +++ b/core/utils/EditableContext.ts @@ -0,0 +1,12 @@ +import * as React from 'react'; + +type EditableContext = { + editable: boolean; +}; + +const editableContext = React.createContext({ + editable: false, +}); + +export const EditableProvider = editableContext.Provider; +export default editableContext; diff --git a/core/utils/__tests__/__snapshots__/TS.test.tsx.snap b/core/utils/__tests__/__snapshots__/TS.test.tsx.snap index aebe5bd83c..7e4c8d01f2 100644 --- a/core/utils/__tests__/__snapshots__/TS.test.tsx.snap +++ b/core/utils/__tests__/__snapshots__/TS.test.tsx.snap @@ -2508,6 +2508,7 @@ exports[`TS renders children 1`] = `