Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ 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,
- Deprecated `hideUploadButton` in favor of `disableFileUpload`. Added rectification logic in `patchStyleOptionsFromDeprecatedProps.js`.
- Updated `BasicSendBoxToolbar` to rely solely on `disableFileUpload`.
- Improved test to simulate keyboard and mouse behavior instead of DOM-only checks.
in PR [#5508](https://github.com/microsoft/BotFramework-WebChat/pull/5508), by [@JamesNewbyAtMicrosoft](https://github.com/JamesNewbyAtMicrosoft)
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated

Comment thread
OEvgeny marked this conversation as resolved.
### Changed

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.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.
89 changes: 89 additions & 0 deletions __tests__/html2/basic/disableFileUpload.html
Comment thread
OEvgeny marked this conversation as resolved.
Comment thread
OEvgeny marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!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();

WebChat.renderWebChat(
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated
{
directLine,
store,
styleOptions: { disableFileUpload: true }
},
document.getElementById('webchat')
);

await pageConditions.uiConnected();

// DOM-based checks
expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy();
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy();

// Keyboard interaction: try to tab to the upload button
await pageObjects.focusSendBoxTextBox();
await host.sendTab();
console.log('document.activeElement', document.activeElement);
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated

expect(document.activeElement).not.toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton));

// Simulate drag-and-drop using dispatchEvent
const sendBox = document.querySelector('[role="form"]');
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated
if (sendBox) {
const dataTransfer = new DataTransfer();
const file = new File(['dummy content'], 'test.txt', { type: 'text/plain' });
dataTransfer.items.add(file);

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

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

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

sendBox.dispatchEvent(dragEnterEvent);
sendBox.dispatchEvent(dragOverEvent);
sendBox.dispatchEvent(dropEvent);

// Drop zone should still not appear
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy();

// Attachment bar item should not appear
expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeFalsy();

await host.snapshot('drag-and-drop-disabled');
}
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated

// Hover interaction: hover over the send box area
await host.hover(document.querySelector('[role="form"]'));
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated
await host.snapshot('hover-over-sendbox-toolbar');
Comment thread
JamesNewbyAtMicrosoft marked this conversation as resolved.
Outdated

// Final visual confirmation
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.
17 changes: 17 additions & 0 deletions 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 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: false,
microphoneButtonColorOnDictate: '#F33',
sendAttachmentOn: 'send',
sendBoxBackground: 'White',
uploadAccept: undefined,
uploadMultiple: true,
sendAttachmentOn: 'send',

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

// Rectify deprecated "hideUploadButton" into "disableFileUpload"
if ('hideUploadButton' in styleOptions && !('disableFileUpload' in styleOptions)) {
console.warn('Web Chat: "hideUploadButton" is deprecated. Please use "disableFileUpload" instead.');
Comment thread
OEvgeny marked this conversation as resolved.
Outdated

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

return styleOptions;
}
Comment thread
OEvgeny marked this conversation as resolved.
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: 8 additions & 1 deletion packages/component/src/SendBoxToolbar/UploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useMakeThumbnail from '../hooks/useMakeThumbnail';
import useStyleSet from '../hooks/useStyleSet';
import useSubmit from '../providers/internal/SendBox/useSubmit';
import AttachmentIcon from './Assets/AttachmentIcon';
import testIds from '../testIds';

const { useSendBoxAttachments, useLocalizer, useStyleOptions, useUIState } = hooks;

Expand Down Expand Up @@ -120,7 +121,13 @@ function UploadButton(props: UploadButtonProps) {
tabIndex={-1}
type="file"
/>
<IconButton alt={uploadFileString} aria-label={uploadFileString} disabled={disabled} onClick={handleClick}>
<IconButton
alt={uploadFileString}
aria-label={uploadFileString}
data-testid={testIds.basicSendBoxUploadButton}
disabled={disabled}
onClick={handleClick}
>
<AttachmentIcon checked={!!sendBoxAttachments.length} />
</IconButton>
</div>
Expand Down
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
1 change: 1 addition & 0 deletions packages/component/src/testIds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const testIds = {
basicSendBoxUploadButton: 'basic send box toolbar upload button',
codeBlockCopyButton: 'code block copy button',
copyButton: 'copy button',
feedbackButton: 'feedback button',
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