Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
239161d
adding hideUploadButton boolean to file upload dropzone and adding to…
JamesNewbyAtMicrosoft Jul 2, 2025
64e5fab
adding space
JamesNewbyAtMicrosoft Jul 2, 2025
9b8d3b3
adding changelog details
JamesNewbyAtMicrosoft Jul 2, 2025
3efb9bc
Merge branch 'main' into janewby/WebChat
JamesNewbyAtMicrosoft Jul 2, 2025
187d415
replacing hideAttachFileButton flag with disableFileUpload
JamesNewbyAtMicrosoft Jul 4, 2025
1c179db
adding for backward compat
JamesNewbyAtMicrosoft Jul 7, 2025
38ad2a0
Merge remote-tracking branch 'origin' into janewby/WebChat
OEvgeny Jul 14, 2025
22fe08c
Bring back old tests
OEvgeny Jul 14, 2025
f905b3a
Rework disableFileUpload:
OEvgeny Jul 14, 2025
ba66c60
Update packages/api/src/StyleOptions.ts
OEvgeny Jul 14, 2025
f5ef7ae
Sort
OEvgeny Jul 14, 2025
88dc42f
added testing for drag and drop, deprecation patch, and removed dual …
JamesNewbyAtMicrosoft Jul 23, 2025
c13ee36
Merge branch 'main' into janewby/WebChat
JamesNewbyAtMicrosoft Jul 23, 2025
2d8e366
Merge branch 'main' into janewby/WebChat
JamesNewbyAtMicrosoft Jul 31, 2025
088f92e
commit snapshots
JamesNewbyAtMicrosoft Jul 31, 2025
5c4b931
updated test to comments
JamesNewbyAtMicrosoft Jul 31, 2025
3df7b65
Update CHANGELOG.md
JamesNewbyAtMicrosoft Jul 31, 2025
c167376
Improve test and cover false scenario
OEvgeny Aug 1, 2025
48e411b
cleanup
OEvgeny Aug 1, 2025
717cba4
Cleanup
OEvgeny Aug 1, 2025
1c9b1ad
Remove unused test id
OEvgeny Aug 1, 2025
e30cc31
fix warning display
OEvgeny Aug 1, 2025
dc189ef
Improve message
OEvgeny Aug 1, 2025
2d4adc4
Fix nits
OEvgeny Aug 1, 2025
58ecaea
Changelog
OEvgeny Aug 1, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
- `activityGroupingDecoratorMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
- `sendBoxMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
- `sendBoxToolbarMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
- `styleOptions.hideUploadButton` is being deprecated in favor of `styleOptions.disableFileUpload`. The option will be removed on or after 2027-07-14

### Added

Expand Down Expand Up @@ -102,6 +103,9 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
- Attaching files will no longer remove previously attached files
- Updated Fluent theme to use the new attachment preview feature
- Added collapsible activity and activity with abstract handling, in PR [#5506](https://github.com/microsoft/BotFramework-WebChat/pull/5506), in PR [#5513](https://github.com/microsoft/BotFramework-WebChat/pull/5513), by [@OEvgeny](https://github.com/OEvgeny)
- Added `disableFileUpload` flag to completelly disable file upload feature, in PR [#5508](https://github.com/microsoft/BotFramework-WebChat/pull/5508), by [@JamesNewbyAtMicrosoft](https://github.com/JamesNewbyAtMicrosoft)
- Deprecated `hideUploadButton` in favor of `disableFileUpload`.
- Updated `BasicSendBoxToolbar` to rely solely on `disableFileUpload`.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions __tests__/html/fluentTheme/hideAttachFileButton.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
WebChat: { FluentThemeProvider, ReactWebChat }
} = window; // Imports in UMD fashion.

const warnings = [];
const warn = console.warn.bind(console);
console.warn = (message) => {
warnings.push(message);
warn(message);
};

const { directLine, store } = testHelpers.createDirectLineEmulator();

const App = () => (
Expand All @@ -34,10 +41,15 @@
);

await pageConditions.uiConnected();

expect(warnings).toEqual([
'botframework-webchat: `styleOptions.hideUploadButton` is being deprecated in favor of `styleOptions.disableFileUpload`. The option will be removed on or after 2027-07-14.'
]);

// THEN: No attach button should be render.
expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy();
await host.snapshot();

});
</script>
</body>
Expand Down
10 changes: 10 additions & 0 deletions __tests__/html2/basic/disableFileUpload.copilot.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>Disable file upload (copilot)</title>
<script>
location = './disableFileUpload?theme=fluent&variant=copilot';
</script>
</head>
<body></body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions __tests__/html2/basic/disableFileUpload.false.fluent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>Disable file upload (false) (fluent)</title>
<script>
location = './disableFileUpload?disableFileUpload=false&theme=fluent';
</script>
</head>
<body></body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions __tests__/html2/basic/disableFileUpload.fluent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>Disable file upload (fluent)</title>
<script>
location = './disableFileUpload?theme=fluent';
</script>
</head>
<body></body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions __tests__/html2/basic/disableFileUpload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Disable file upload</title>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
<script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
</head>
<body>
<main id="webchat"></main>
<script>
run(async function () {
const { directLine, store } = testHelpers.createDirectLineEmulator();

const disableFileUpload = new URLSearchParams(location.search || '').get('disableFileUpload') !== 'false';
const { isFluentTheme } = renderWebChat(
{
directLine,
store,
styleOptions: { disableFileUpload }
},
document.getElementById('webchat')
);

await pageConditions.uiConnected();

// DOM-based checks
if (disableFileUpload) {
expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy();
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy();
} else {
expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeDefined();
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeDefined();
}

// Keyboard interaction: try to tab to the upload button
await pageObjects.focusSendBoxTextBox();
await host.sendTab();

if (disableFileUpload) {
expect(document.activeElement).not.toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton));
} else {
expect(document.activeElement).toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton));
}

if (isFluentTheme) {
// We cannot mimic drag-and-drop in WebDriver yet. So we are doing as good as we could.
const dataTransfer = new DataTransfer();

dataTransfer.items.add(new File([new ArrayBuffer(100)], 'simple.txt'));

const dragEnterDocumentEvent = new DragEvent('dragenter', {
bubbles: true,
cancelable: true,
dataTransfer
});

document.dispatchEvent(dragEnterDocumentEvent);

const dropEvent = new DragEvent('drop', {
bubbles: true,
cancelable: true,
dataTransfer
});

document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`)?.dispatchEvent(dropEvent);

if (disableFileUpload) {
// Attachment bar item should not appear
expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeFalsy();
} else {
// Attachment bar item should appear
expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeDefined();
}
}

await host.snapshot('local');
});
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion packages/api/src/StyleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ type StyleOptions = {
*/

hideSendBox?: boolean;

/**
* Indicates if the upload file button should be hidden.
*
* @default false
*
* @deprecated deprecated since 4.18.0: obsolated by {@linkcode disableFileUpload}. This option will be removed on or after 2027-07-14.
*/
hideUploadButton?: boolean;

/**
Expand Down Expand Up @@ -976,6 +984,15 @@ type StyleOptions = {
* @default 3
*/
sendBoxAttachmentBarMaxThumbnail?: number;

/**
* Indicates if file upload should be disabled.
*
* @default false
*
* New in 4.19.0.
*/
disableFileUpload?: boolean;
};

// StrictStyleOptions is only used internally in Web Chat and for simplifying our code:
Expand All @@ -985,7 +1002,12 @@ type StyleOptions = {
type StrictStyleOptions = Required<
Omit<
StyleOptions,
'bubbleImageHeight' | 'bubbleMaxWidth' | 'bubbleMinWidth' | 'hideScrollToEndButton' | 'newMessagesButtonFontSize'
| 'bubbleImageHeight'
| 'bubbleMaxWidth'
| 'bubbleMinWidth'
| 'hideScrollToEndButton'
| 'hideUploadButton'
| 'newMessagesButtonFontSize'
>
> & {
bubbleFromUserNubOffset: number;
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/defaultStyleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ const DEFAULT_OPTIONS: Required<StyleOptions> = {
autoScrollSnapOnPageOffset: 0, // TODO: Rename from "autoScrollSnapOnPageoffset".

// Send box
disableFileUpload: false,
hideSendBox: false,
hideUploadButton: false,
hideTelephoneKeypadButton: true,
hideUploadButton: undefined, // Deprecated as of 4.19.0.
microphoneButtonColorOnDictate: '#F33',
sendAttachmentOn: 'send',
sendBoxBackground: 'White',
uploadAccept: undefined,
uploadMultiple: true,
sendAttachmentOn: 'send',

// Send box buttons
sendBoxButtonColor: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/patchStyleOptionsFromDeprecatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ export default function patchStyleOptionsFromDeprecatedProps(styleOptions) {
styleOptions = updateIn(styleOptions, ['slowConnectionAfter'], () => 0);
}

// Rectify deprecated "hideUploadButton" into "disableFileUpload"
if (styleOptions.hideUploadButton !== undefined) {
console.warn(
'botframework-webchat: `styleOptions.hideUploadButton` is being deprecated in favor of `styleOptions.disableFileUpload`. The option will be removed on or after 2027-07-14.'
);

styleOptions = updateIn(styleOptions, ['disableFileUpload'], () => !!styleOptions.hideUploadButton);
}

return styleOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import UploadButton from './UploadButton';

const { useStyleOptions } = hooks;

// NOTE: "hideUploadButton" is deprecated. Use "disableFileUpload" instead.
// Rectification logic is handled in patchStyleOptionsFromDeprecatedProps.js
function BasicSendBoxToolbar({ className }: SendBoxToolbarMiddlewareProps) {
const [{ hideUploadButton }] = useStyleOptions();
const [{ disableFileUpload }] = useStyleOptions();

return !hideUploadButton && <UploadButton className={className} />;
return !disableFileUpload && <UploadButton className={className} />;
}

export default memo(BasicSendBoxToolbar);
9 changes: 9 additions & 0 deletions packages/component/src/Styles/StyleSet/SendBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function createSendBoxStyle({
flexDirection: 'column',
// eslint-disable-next-line no-magic-numbers
gap: `${paddingRegular / 2}px`,
gridArea: 'text-box',
// eslint-disable-next-line no-magic-numbers
paddingBottom: `${paddingRegular / 2}px`,
// eslint-disable-next-line no-magic-numbers
Expand All @@ -60,6 +61,14 @@ export default function createSendBoxStyle({
'& .webchat__send-box__attachment-bar': {
padding: `${paddingRegular}px`,
paddingBlockEnd: `0px`
},

'& .webchat__upload-button': {
gridArea: 'upload-button'
},

'& .webchat__send-button': {
gridArea: 'send-button'
}
}
} satisfies StyleSet;
Expand Down
6 changes: 3 additions & 3 deletions packages/fluent-theme/src/components/sendBox/SendBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Props = Readonly<{
}>;

function SendBox(props: Props) {
const [{ hideTelephoneKeypadButton, hideUploadButton, maxMessageLength }] = useStyleOptions();
const [{ disableFileUpload, hideTelephoneKeypadButton, maxMessageLength }] = useStyleOptions();
const [attachments, setAttachments] = useSendBoxAttachments();
const [globalMessage, setGlobalMessage] = useSendBoxValue();
const [localMessage, setLocalMessage] = useState('');
Expand Down Expand Up @@ -238,7 +238,7 @@ function SendBox(props: Props) {
)}
<Toolbar>
{!hideTelephoneKeypadButton && <TelephoneKeypadToolbarButton />}
{!hideUploadButton && <AddAttachmentButton onFilesAdded={handleAddFiles} />}
{!disableFileUpload && <AddAttachmentButton onFilesAdded={handleAddFiles} />}
<ToolbarSeparator />
<ToolbarButton
aria-label={localize('TEXT_INPUT_SEND_BUTTON_ALT')}
Expand All @@ -250,7 +250,7 @@ function SendBox(props: Props) {
</ToolbarButton>
</Toolbar>
</div>
<DropZone onFilesAdded={handleAddFiles} />
{!disableFileUpload && <DropZone onFilesAdded={handleAddFiles} />}
<ErrorMessage error={errorMessage} id={errorMessageId} />
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Sample - Disable the Upload Button

- Prevent users from sending attachments to the bot by disabling the upload button.
- Prevent users from sending attachments to the bot by disabling the upload button.

# Test out the hosted sample

- [Try out MockBot](https://microsoft.github.io/BotFramework-WebChat/02.branding-styling-and-customization/f.hide-upload-button)
- [Try out MockBot](https://microsoft.github.io/BotFramework-WebChat/02.branding-styling-and-customization/f.hide-upload-button)

# How to run

- Fork this repository
- Navigate to `/Your-Local-WebChat/samples/02.branding-styling-and-customization/f.hide-upload-button` in command line
- Run `npx serve`
- Browse to [http://localhost:5000/](http://localhost:5000/)
- Fork this repository
- Navigate to `/Your-Local-WebChat/samples/02.branding-styling-and-customization/f.hide-upload-button` in command line
- Run `npx serve`
- Browse to [http://localhost:5000/](http://localhost:5000/)

# Things to try out

- Note that there is no upload button in the Send Box
- Note that there is no upload button in the Send Box

# Code

Expand All @@ -31,7 +31,7 @@ By modifying the `styleOptions` object passed into the renderer, we can disable
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
+ styleOptions: {
+ hideUploadButton: true
+ disableFileUpload: true
+ }
}, document.getElementById('webchat'));
```
Expand Down Expand Up @@ -75,7 +75,7 @@ Here is the finished `index.html`:
{
directLine: window.WebChat.createDirectLine({ token }),
styleOptions: {
hideUploadButton: true
disableFileUpload: true
}
},
document.getElementById('webchat')
Expand All @@ -91,7 +91,7 @@ Here is the finished `index.html`:

# Further reading

- [Branding styling bot](https://microsoft.github.io/BotFramework-WebChat/02.branding-styling-and-customization/a.branding-web-chat) | [(Branding styling source code)](https://github.com/microsoft/BotFramework-WebChat/tree/main/samples/02.branding-styling-and-customization/a.branding-web-chat)
- [Branding styling bot](https://microsoft.github.io/BotFramework-WebChat/02.branding-styling-and-customization/a.branding-web-chat) | [(Branding styling source code)](https://github.com/microsoft/BotFramework-WebChat/tree/main/samples/02.branding-styling-and-customization/a.branding-web-chat)

## Full list of Web Chat hosted samples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{
directLine: window.WebChat.createDirectLine({ token }),
styleOptions: {
hideUploadButton: true
disableFileUpload: true
}
},
document.getElementById('webchat')
Expand Down
Loading