fix(device-selection): do not create a dropdown menu if disabled

AtlasKit DropdownMenu cannot be disabled, unlike Single Select.
The result is the isDisabled prop was not being honored. The
workaround is returning only the trigger element for the dropdown
and styling it to look like the dropdown is disabled. The text
for disabled device selection was changed along the way to fit
into the trigger.
This commit is contained in:
Leonard Kim 2017-04-25 09:15:15 -07:00
parent 00b4176bf8
commit 4e95dbf0e5
3 changed files with 23 additions and 10 deletions

View File

@ -36,6 +36,12 @@
background-color: rgba(9,30,66,.08); background-color: rgba(9,30,66,.08);
} }
} }
.device-selector-trigger-disabled {
.device-selector-trigger {
color: #a5adba;
cursor: default;
}
}
.device-selector-trigger-text { .device-selector-trigger-text {
overflow: hidden; overflow: hidden;

View File

@ -149,7 +149,6 @@
"selectAudioOutput": "Audio output", "selectAudioOutput": "Audio output",
"followMe": "Everyone follows me", "followMe": "Everyone follows me",
"noDevice": "None", "noDevice": "None",
"noPermission": "Permission to use device is not granted",
"cameraAndMic": "Camera and microphone", "cameraAndMic": "Camera and microphone",
"moderator": "MODERATOR", "moderator": "MODERATOR",
"password": "SET PASSWORD", "password": "SET PASSWORD",
@ -423,7 +422,7 @@
"deviceSelection": { "deviceSelection": {
"currentlyVideoMuted": "Video is currently muted", "currentlyVideoMuted": "Video is currently muted",
"deviceSettings": "Device settings", "deviceSettings": "Device settings",
"noOtherDevices": "No other devices available", "noPermission": "Permission not granted",
"selectADevice": "Select a device", "selectADevice": "Select a device",
"testAudio": "Test sound" "testAudio": "Test sound"
}, },

View File

@ -138,13 +138,15 @@ class DeviceSelector extends Component {
} }
/** /**
* Creates a AKDropdownMenu Component using passed in props and options. * Creates a AKDropdownMenu Component using passed in props and options. If
* the dropdown needs to be disabled, then only the AKDropdownMenu trigger
* element is returned to simulate a disabled state.
* *
* @param {Object} options - Additional configuration for display. * @param {Object} options - Additional configuration for display.
* @param {Object} options.defaultSelected - The option that should be set * @param {Object} options.defaultSelected - The option that should be set
* as currently chosen. * as currently chosen.
* @param {boolean} options.isDisabled - If true, AKDropdownMenu will not * @param {boolean} options.isDisabled - If true, only the AKDropdownMenu
* open on click. * trigger component will be returned to simulate a disabled dropdown.
* @param {Array} options.items - All the selectable options to display. * @param {Array} options.items - All the selectable options to display.
* @param {string} options.placeholder - The translation key to display when * @param {string} options.placeholder - The translation key to display when
* no selection has been made. * no selection has been made.
@ -155,16 +157,22 @@ class DeviceSelector extends Component {
const triggerText const triggerText
= (options.defaultSelected && options.defaultSelected.content) = (options.defaultSelected && options.defaultSelected.content)
|| options.placeholder; || options.placeholder;
const trigger = this._createDropdownTrigger(triggerText);
if (options.isDisabled) {
return (
<div className = 'device-selector-trigger-disabled'>
{ trigger }
</div>
);
}
return ( return (
<AKDropdownMenu <AKDropdownMenu
{ ...(options.isDisabled && { isOpen: !options.isDisabled }) }
items = { [ { items: options.items || [] } ] } items = { [ { items: options.items || [] } ] }
noMatchesFound
= { this.props.t('deviceSelection.noOtherDevices') }
onItemActivated = { this._onSelect } onItemActivated = { this._onSelect }
shouldFitContainer = { true }> shouldFitContainer = { true }>
{ this._createDropdownTrigger(triggerText) } { trigger }
</AKDropdownMenu> </AKDropdownMenu>
); );
} }
@ -208,7 +216,7 @@ class DeviceSelector extends Component {
_renderNoPermission() { _renderNoPermission() {
return this._createDropdown({ return this._createDropdown({
isDisabled: true, isDisabled: true,
placeholder: this.props.t('settings.noPermission') placeholder: this.props.t('deviceSelection.noPermission')
}); });
} }
} }