Skip to content
Draft
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
13 changes: 2 additions & 11 deletions apps/react-storybook/stories/examples/selectbox/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import React from 'react';
import TextBox from 'devextreme-react/text-box';

const nameLabel = { 'aria-label': 'Name' };

export default function Field(data: { ImageSrc: any; Name: any }) {
return (
<div className="custom-item">
<div className="custom-addon">
<img
alt="Product name"
src={data && data.ImageSrc}
/>
<TextBox
className="product-name"
inputAttr={nameLabel}
defaultValue={data && data.Name}
readOnly={true}
src={data?.ImageSrc}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react-webpack5';

import React, { useCallback, useState } from 'react';
import SelectBox, { SelectBoxTypes } from 'devextreme-react/select-box';
import SelectBox, { FieldAddons, SelectBoxTypes } from 'devextreme-react/select-box';
import notify from 'devextreme/ui/notify';

import service from "./data";
Expand Down Expand Up @@ -80,9 +80,13 @@ export const CustomTemplates: Story = {
inputAttr: templatedProductLabel,
valueExpr: "ID",
defaultValue: products[3].ID,
fieldRender: Field,
itemRender: Item
},
render: (args) => (
<SelectBox {...args}>
<FieldAddons beforeRender={Field} />
</SelectBox>
),
}

export const EventHandling: Story = {
Expand Down
6 changes: 6 additions & 0 deletions apps/react-storybook/stories/examples/selectbox/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
min-height: 30px;
}

.custom-addon {
padding-left: 8px;
display: flex;
align-items: center;
}

.dx-dropdowneditor-input-wrapper .custom-item > img {
padding-left: 8px;
}
Expand Down
17 changes: 1 addition & 16 deletions apps/react/examples/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import ToolbarExample from './toolbar-example';
import ValidationExample from './validation-example';
// import DateBoxExample from './date-box-example';
import SelectBoxTemplatesExample from './selectbox-templates-example';
import SelectBoxFieldTemplateExample from './selectbox-fieldtemplate-example';
import SelectBoxParallelTemplateRenderExample from './selectbox-parallel-template-render-example';
import TagBoxFieldTemplateCheckBoxesExample from './tagbox-fieldtemplate-checkboxes-example';
import FormWithNestedExample from './form-with-nested';


Expand Down Expand Up @@ -93,22 +90,10 @@ const Examples = () => {
<SelectBoxExample />
</Example>

<Example title="SelectBox example with templates for item and field">
<Example title="SelectBox example with templates for item and field addon">
<SelectBoxTemplatesExample />
</Example>

<Example title="TagBox with field template and showSelectionControls=true">
<TagBoxFieldTemplateCheckBoxesExample />
</Example>

<Example title="SelectBox example with field template (controlled mode)">
<SelectBoxFieldTemplateExample />
</Example>

<Example title="SelectBox example with field template (parallel render)">
<SelectBoxParallelTemplateRenderExample />
</Example>

{/*<StandaloneValidatorExample />*/}

</div>
Expand Down
7 changes: 1 addition & 6 deletions apps/react/examples/editor-example.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import * as React from 'react';
import { SelectBox } from 'devextreme-react/select-box';
import { TagBox } from 'devextreme-react/tag-box';
import { TextBox } from 'devextreme-react/text-box';
import Example from './example-block';

function fieldRender() {
return <TextBox value="123" />;
}

export default class extends React.Component<any, any> {
public render(): React.ReactNode {
return (
<Example title="Editors" state={this.state}>
<SelectBox fieldRender={fieldRender} />
<SelectBox />
<br />
<TagBox dataSource={['1', '2', '3']} showClearButton tagRender={() => <div>test</div>} />
</Example>
Expand Down
67 changes: 0 additions & 67 deletions apps/react/examples/selectbox-fieldtemplate-example.tsx

This file was deleted.

55 changes: 0 additions & 55 deletions apps/react/examples/selectbox-parallel-template-render-example.tsx

This file was deleted.

21 changes: 6 additions & 15 deletions apps/react/examples/selectbox-templates-example.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useCallback, useState } from "react";
import { SelectBoxTypes } from "devextreme-react/select-box";
import { FieldAddons, SelectBoxTypes } from "devextreme-react/select-box";
import { SelectBox } from "devextreme-react";
import { TextBox } from "devextreme-react";

const products = [{
ID: 1,
Expand All @@ -24,7 +23,6 @@ const products = [{
}];

const templatedProductLabel = { "aria-label": "Templated Product" };
const nameLabel = { "aria-label": "Name" };
function Item(data) {
return (
<div className="custom-item">
Expand All @@ -39,18 +37,10 @@ function Item(data) {

function Field(data: { ImageSrc: any; Name: any }) {
return (
<div className="custom-item">
<div className="value">{data.Name}</div>
<div className="custom-addon">
<img
alt="Product name"
src={data && data.ImageSrc} />
<TextBox
value= {data?.Name || ''}
className="product-name"
inputAttr={nameLabel}
defaultValue={data && data.Name}
readOnly={true}
/>
src={data?.ImageSrc} />
</div>
);
}
Expand All @@ -74,9 +64,10 @@ function SelectBoxCustomExample() {
inputAttr={templatedProductLabel}
valueExpr="ID"
defaultValue={products[0].ID}
fieldRender={Field}
itemRender={Item}
/>
>
<FieldAddons beforeRender={Field} />
</SelectBox>
</div>
);
}
Expand Down
19 changes: 0 additions & 19 deletions apps/react/examples/tagbox-fieldtemplate-checkboxes-example.tsx

This file was deleted.

53 changes: 3 additions & 50 deletions e2e/playwright/tests/editors/selectBox/actionButton.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import SelectBox from '../../../models/selectBox';
const FOCUSED_STATE_CLASS = 'dx-state-focused';

interface ActionButtonOptions {
refocus?: boolean;
type?: string;
disabled?: boolean;
}

const setActionButton = async (
page: Page,
{ refocus = false, ...buttonOptions }: ActionButtonOptions = {},
): Promise<void> => page.evaluate(({ shouldRefocus, options }) => {
buttonOptions: ActionButtonOptions = {},
): Promise<void> => page.evaluate((options) => {
const selectBox = ($('#container') as any).dxSelectBox('instance');

selectBox.option('buttons', [{
Expand All @@ -26,58 +25,12 @@ const setActionButton = async (
...options,
onClick: () => {
selectBox.option('value', 'item2');

if (shouldRefocus) {
// The editor rerenders its input.
selectBox.focus();
}
},
},
}]);
}, { shouldRefocus: refocus, options: buttonOptions });
}, buttonOptions);

test.describe('SelectBox', () => {
test('Click on action button should correctly work with SelectBox containing the field template (T811890)', async ({ page }) => {
await createWidget(page, 'dxSelectBox', () => ({
items: ['item1', 'item2'],
fieldTemplate: (value) => ($('<div>') as any).dxTextBox({ value }),
}));

const selectBox = new SelectBox(page, '#container');

await setActionButton(page, { refocus: true });

await selectBox.element.click();
await page.keyboard.press('Alt+ArrowUp');
await selectBox.expectFocused();
await expect.poll(() => selectBox.isOpened()).toBe(false);

await selectBox.getButton(0).element.click();
await selectBox.expectFocused();
await expect(selectBox.input).toHaveValue('item2');
});

test('Click on action button after typing should correctly work with SelectBox containing the field template (T811890)', async ({ page }) => {
await createWidget(page, 'dxSelectBox', () => ({
items: ['item1', 'item2'],
fieldTemplate: (value) => ($('<div>') as any).dxTextBox({ value }),
}));

const selectBox = new SelectBox(page, '#container');

await setActionButton(page, { refocus: true });

await selectBox.element.click();
await page.keyboard.press('Alt+ArrowUp');
await selectBox.expectFocused();
await expect.poll(() => selectBox.isOpened()).toBe(false);

await selectBox.input.pressSequentially('tt');
await selectBox.getButton(0).element.click();
await selectBox.expectFocused();
await expect(selectBox.input).toHaveValue('item2');
});

test('editor can be focused out after click on action button', async ({ page }) => {
await createWidget(page, 'dxSelectBox', {
items: ['item1', 'item2'],
Expand Down
Loading
Loading