diff --git a/src/text-field/README.md b/src/text-field/README.md index d9afed3b..e762cf57 100644 --- a/src/text-field/README.md +++ b/src/text-field/README.md @@ -147,3 +147,30 @@ An icon can be added to the right of the text field by adding an element with th ``` + +### Multiple Icons + +Building on top of the icon examples above, multiple icons can also be inserted into the start and end slots of a text field with the `slot="start"` and `slot="end"` attributes. + +The below example demonstrates how the native search text field from VS Code might be _visually_ implemented with a `section` tag that wraps a few `vscode-buttons` with an icon appearance applied (please note that further JavaScript is needed to make this example functional, however). + +[Interactive Storybook Example](https://microsoft.github.io/vscode-webview-ui-toolkit/?path=/story/library-text-field--with-multiple-icons) + +```html + + + + Text Field Label +
+ + + + + + + + + +
+
+``` diff --git a/src/text-field/fixtures/createTextField.ts b/src/text-field/fixtures/createTextField.ts index 9456ccba..aee6369d 100644 --- a/src/text-field/fixtures/createTextField.ts +++ b/src/text-field/fixtures/createTextField.ts @@ -18,6 +18,7 @@ export type TextFieldArgs = { isAutoFocused: boolean; startIcon: boolean; endIcon: boolean; + multipleIcons: boolean; }; export function createTextField({ @@ -32,6 +33,7 @@ export function createTextField({ isAutoFocused, startIcon, endIcon, + multipleIcons, }: TextFieldArgs) { const textField = new TextField(); @@ -73,6 +75,26 @@ export function createTextField({ const end = createCodiconIcon({iconName: 'text-size', slotName: 'end'}); textField.appendChild(end); } + if (multipleIcons) { + const section = document.createElement('section'); + section.setAttribute('slot', 'end'); + section.style.display = 'flex'; + section.style.alignItems = 'center'; + + section.innerHTML = /*html*/ ` + + + + + + + + + + `; + + textField.appendChild(section); + } return textField; } diff --git a/src/text-field/text-field.stories.ts b/src/text-field/text-field.stories.ts index 02f99da1..a68eb628 100644 --- a/src/text-field/text-field.stories.ts +++ b/src/text-field/text-field.stories.ts @@ -22,6 +22,7 @@ export default { isAutoFocused: {control: 'boolean'}, startIcon: {control: 'boolean'}, endIcon: {control: 'boolean'}, + multipleIcons: {control: 'boolean'}, }, parameters: { actions: { @@ -47,6 +48,7 @@ Default.args = { isAutoFocused: false, startIcon: false, endIcon: false, + multipleIcons: false, }; Default.parameters = { docs: { @@ -177,3 +179,16 @@ WithEndIcon.parameters = { }, }, }; + +export const WithMultipleIcons: any = Template.bind({}); +WithMultipleIcons.args = { + ...Default.args, + multipleIcons: true, +}; +WithMultipleIcons.parameters = { + docs: { + source: { + code: `\n\n\n\tText Field Label\n\t
\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t
\n
`, + }, + }, +};