You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageRecipient.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconCancelSelection } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import AbstractMessageRecipient, {
  7. _mapDispatchToProps,
  8. _mapStateToProps,
  9. type Props
  10. } from '../AbstractMessageRecipient';
  11. /**
  12. * Class to implement the displaying of the recipient of the next message.
  13. */
  14. class MessageRecipient extends AbstractMessageRecipient<Props> {
  15. /**
  16. * Initializes a new {@code MessageRecipient} instance.
  17. *
  18. * @param {*} props - The read-only properties with which the new instance
  19. * is to be initialized.
  20. */
  21. constructor(props) {
  22. super(props);
  23. // Bind event handler so it is only bound once for every instance.
  24. this._onKeyPress = this._onKeyPress.bind(this);
  25. }
  26. _onKeyPress: (Object) => void;
  27. /**
  28. * KeyPress handler for accessibility.
  29. *
  30. * @param {Object} e - The key event to handle.
  31. *
  32. * @returns {void}
  33. */
  34. _onKeyPress(e) {
  35. if (this.props._onRemovePrivateMessageRecipient && (e.key === ' ' || e.key === 'Enter')) {
  36. e.preventDefault();
  37. this.props._onRemovePrivateMessageRecipient();
  38. }
  39. }
  40. /**
  41. * Implements {@code PureComponent#render}.
  42. *
  43. * @inheritdoc
  44. */
  45. render() {
  46. const { _privateMessageRecipient } = this.props;
  47. if (!_privateMessageRecipient) {
  48. return null;
  49. }
  50. const { t } = this.props;
  51. return (
  52. <div
  53. id = 'chat-recipient'
  54. role = 'alert'>
  55. <span>
  56. { t('chat.messageTo', {
  57. recipient: _privateMessageRecipient
  58. }) }
  59. </span>
  60. <div
  61. aria-label = { t('dialog.close') }
  62. onClick = { this.props._onRemovePrivateMessageRecipient }
  63. onKeyPress = { this._onKeyPress }
  64. role = 'button'
  65. tabIndex = { 0 }>
  66. <Icon
  67. src = { IconCancelSelection } />
  68. </div>
  69. </div>
  70. );
  71. }
  72. }
  73. export default translate(connect(_mapStateToProps, _mapDispatchToProps)(MessageRecipient));