CollapseButton.js (1074B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 8 9 const { 10 l10n, 11 } = require("resource://devtools/client/webconsole/utils/messages.js"); 12 const messageToggleDetails = l10n.getStr("messageToggleDetails"); 13 14 function CollapseButton(props) { 15 const { open, onClick, title = messageToggleDetails } = props; 16 17 return dom.button({ 18 "aria-expanded": open ? "true" : "false", 19 "aria-label": title, 20 className: "arrow collapse-button", 21 onClick, 22 onMouseDown: e => { 23 // prevent focus from moving to the disclosure if clicked, 24 // which is annoying if on the input 25 e.preventDefault(); 26 // Clearing the text selection to allow the message to collpase. 27 e.target.ownerDocument.defaultView.getSelection().removeAllRanges(); 28 }, 29 title, 30 }); 31 } 32 33 module.exports = CollapseButton;