Skip to content

Commit

Permalink
feat(plasma): part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
shuga2704 committed Dec 25, 2024
1 parent 52f240a commit 12b6a2a
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,95 @@ describe('plasma-b2c: Select', () => {
cy.get('[id$="tree_level_1"]').should('not.exist');
cy.get('button').should('not.have.focus');
});

it('flow: opening', () => {
cy.viewport(1300, 500);

const Component = () => {
const [valueSingle, setValueSingle] = React.useState('paris');
const [valueMultiple, setValueMultiple] = React.useState(['paris', 'lyon']);

return (
<CypressTestDecoratorWithTypo>
<div style={{ display: 'flex' }}>
<div style={{ width: '300px' }}>
<Select
id="button-single"
target="button-like"
label="Список стран single"
items={items}
value={valueSingle}
onChange={setValueSingle}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="button-multiple"
multiselect
target="button-like"
label="Список стран single"
items={items}
value={valueMultiple}
onChange={setValueMultiple}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="textfield-single"
target="textfield-like"
items={items}
value={valueSingle}
onChange={setValueSingle}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="textfield-multiple"
multiselect
target="textfield-like"
items={items}
value={valueMultiple}
onChange={setValueMultiple}
/>
</div>
</div>
</CypressTestDecoratorWithTypo>
);
};

mount(<Component />);

cy.get('#button-single').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-single').click();
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#button-single .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-single .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#button-multiple').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-multiple').click();
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#button-multiple .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-multiple .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#textfield-single').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#textfield-single').click();
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#textfield-multiple').realClick({ position: 'topLeft' });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#textfield-multiple').realClick({ position: 'topLeft' });
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#textfield-multiple').realClick({ position: 'center' });
cy.get('ul[role="tree"]').should('not.exist');
});
});
23 changes: 5 additions & 18 deletions packages/plasma-new-hope/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Context } from './Select.context';
export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectProps, 'items'>>) =>
forwardRef<HTMLButtonElement, MergedSelectProps>((props, ref) => {
const {
id,
value: outerValue,
onChange: outerOnChange,
target = 'textfield-like',
Expand Down Expand Up @@ -125,12 +126,12 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
newValue?: string | number | Array<string | number> | ChangeEvent<HTMLSelectElement> | null,
) => {
if (outerOnChange) {
// Условие для отправки если комбобокс используется без формы.
// Условие для отправки если компонент используется без формы.
if (!name && (typeof newValue === 'string' || Array.isArray(newValue))) {
outerOnChange(newValue as any);
}

// Условие для отправки если комбобокс используется с формой.
// Условие для отправки если компонент используется с формой.
if (name && typeof newValue === 'object' && !Array.isArray(newValue)) {
outerOnChange(newValue as any);
}
Expand All @@ -142,20 +143,6 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
}
};

const handleClickArrow = () => {
if (disabled) {
return;
}

if (isCurrentListOpen) {
dispatchPath({ type: 'reset' });
} else {
dispatchPath({ type: 'opened_first_level' });
}

dispatchFocusedPath({ type: 'reset' });
};

const handleListToggle = (opened: boolean) => {
if (disabled) {
return;
Expand Down Expand Up @@ -308,6 +295,7 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
labelPlacement={labelPlacement}
chipView={chipView}
disabled={disabled}
id={id}
{...(rest as any)}
>
{name && (
Expand Down Expand Up @@ -337,7 +325,7 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
<FloatingPopover
ref={floatingPopoverRef}
opened={isCurrentListOpen}
onToggle={(opened: boolean) => opened && handleListToggle(true)}
onToggle={handleListToggle}
placement={placement}
portal={portal}
listWidth={listWidth}
Expand All @@ -359,7 +347,6 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
inputWrapperRef={referenceRef as React.MutableRefObject<HTMLDivElement>}
multiselect={props.multiselect}
view={view}
handleClickArrow={handleClickArrow}
helperText={helperText}
treeId={treeId}
activeDescendantItemValue={activeDescendantItemValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const Target = forwardRef<HTMLButtonElement, TargetProps>(
inputWrapperRef,
multiselect,
view,
handleClickArrow,
helperText,
treeId,
activeDescendantItemValue,
Expand Down Expand Up @@ -79,7 +78,6 @@ export const Target = forwardRef<HTMLButtonElement, TargetProps>(
labelPlacement={labelPlacement}
size={size}
view={view}
handleClickArrow={handleClickArrow}
contentLeft={contentLeft}
helperText={helperText}
treeId={treeId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type TargetProps = Pick<
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
selectProps: MergedSelectProps;
inputWrapperRef: MutableRefObject<HTMLDivElement>;
handleClickArrow: () => void;
treeId: string;
activeDescendantItemValue: string;
onChange: (newValue: string | number | Array<string | number>) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Textfield = forwardRef<HTMLInputElement, TextfieldProps>(
onKeyDown,
size,
view,
handleClickArrow,
contentLeft,
helperText,
treeId,
Expand Down Expand Up @@ -109,7 +108,7 @@ export const Textfield = forwardRef<HTMLInputElement, TextfieldProps>(
placeholder={value instanceof Array && value.length ? '' : placeholder}
contentLeft={contentLeft as React.ReactElement}
contentRight={
<IconArrowWrapper disabled={Boolean(disabled)} onClick={handleClickArrow}>
<IconArrowWrapper disabled={Boolean(disabled)}>
<StyledArrow color="inherit" size={sizeToIconSize(size)} className={withArrowInverse} />
</IconArrowWrapper>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type TextfieldProps = Pick<
| 'onKeyDown'
| 'size'
| 'view'
| 'handleClickArrow'
| 'contentLeft'
| 'helperText'
| 'treeId'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,95 @@ describe('plasma-web: Select', () => {
cy.get('[id$="tree_level_1"]').should('not.exist');
cy.get('button').should('not.have.focus');
});

it('flow: opening', () => {
cy.viewport(1300, 500);

const Component = () => {
const [valueSingle, setValueSingle] = React.useState('paris');
const [valueMultiple, setValueMultiple] = React.useState(['paris', 'lyon']);

return (
<CypressTestDecoratorWithTypo>
<div style={{ display: 'flex' }}>
<div style={{ width: '300px' }}>
<Select
id="button-single"
target="button-like"
label="Список стран single"
items={items}
value={valueSingle}
onChange={setValueSingle}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="button-multiple"
multiselect
target="button-like"
label="Список стран single"
items={items}
value={valueMultiple}
onChange={setValueMultiple}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="textfield-single"
target="textfield-like"
items={items}
value={valueSingle}
onChange={setValueSingle}
/>
</div>

<div style={{ width: '300px' }}>
<Select
id="textfield-multiple"
multiselect
target="textfield-like"
items={items}
value={valueMultiple}
onChange={setValueMultiple}
/>
</div>
</div>
</CypressTestDecoratorWithTypo>
);
};

mount(<Component />);

cy.get('#button-single').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-single').click();
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#button-single .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-single .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#button-multiple').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-multiple').click();
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#button-multiple .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#button-multiple .select-target-arrow').click({ force: true });
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#textfield-single').click();
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#textfield-single').click();
cy.get('ul[role="tree"]').should('not.exist');

cy.get('#textfield-multiple').realClick({ position: 'topLeft' });
cy.get('ul[role="tree"]').should('be.visible');
cy.get('#textfield-multiple').realClick({ position: 'topLeft' });
cy.get('ul[role="tree"]').should('not.exist');
cy.get('#textfield-multiple').realClick({ position: 'center' });
cy.get('ul[role="tree"]').should('not.exist');
});
});

0 comments on commit 12b6a2a

Please sign in to comment.