diff --git a/app/renderer/components/bookmarks/addEditBookmarkHanger.js b/app/renderer/components/bookmarks/addEditBookmarkHanger.js index f1ec6145087..87e836c0b5a 100644 --- a/app/renderer/components/bookmarks/addEditBookmarkHanger.js +++ b/app/renderer/components/bookmarks/addEditBookmarkHanger.js @@ -113,7 +113,7 @@ class AddEditBookmarkHanger extends React.Component { } render () { - return { this.node = node }} className={cx({ contextMenu: true, diff --git a/app/renderer/components/common/dialog.js b/app/renderer/components/common/dialog.js index 589763b2cb6..8a0f3d2b863 100644 --- a/app/renderer/components/common/dialog.js +++ b/app/renderer/components/common/dialog.js @@ -41,11 +41,13 @@ class Dialog extends ImmutableComponent { } render () { - return
e.button === 1 module.exports.eventElHasAncestorWithClasses = (e, classesToCheck) => { + // DO NOT ADD NEW CHECKS USING THIS METHOD + // classNames are changed from dev to prod by Aphrodite est. v1.2.3 + // and new code will not work. Consider using dataset attribute instead. + // See issue #10029 for a breaking example. + // .... + // TODO deprecate this method. let node = e.target while (node) { @@ -28,3 +34,20 @@ module.exports.eventElHasAncestorWithClasses = (e, classesToCheck) => { return false } + +/** + * Checks if a given node dataset matches a given dataset or array of datasets + * @param {Object} The node to check if dataset is included + * @param {Array|String} the dataset value to check against + * @returns {Boolean} Whether or not the given dataset is included in the check + */ +module.exports.elementHasDataset = (node, datasetArray) => { + if (!node.dataset) { + return false + } + + const datasetToMatch = Array.isArray(datasetArray) ? datasetArray : [datasetArray] + const elementDataset = Object.keys(node.dataset) + + return elementDataset.some(dataset => datasetToMatch.includes(dataset)) +} diff --git a/test/unit/js/lib/eventUtilTest.js b/test/unit/js/lib/eventUtilTest.js new file mode 100644 index 00000000000..c825322421f --- /dev/null +++ b/test/unit/js/lib/eventUtilTest.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* global describe, it */ + +const eventUtil = require('../../../../js/lib/eventUtil') +const assert = require('assert') + +require('../../braveUnit') + +describe('eventUtil', function () { + describe('elementHasDataset', function () { + let datasetToTest + let node = { dataset: { nespresso: true } } + + it('returns false if node dataset do not match', function () { + datasetToTest = ['starbucks', 'keurig'] + assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false) + }) + it('returns true if node dataset match the provided dataset array', function () { + datasetToTest = ['wow', 'such', 'nespresso', 'very', 'amazing'] + assert.equal(eventUtil.elementHasDataset(node, datasetToTest), true) + }) + it('can accept strings for the dataset to match against', function () { + datasetToTest = 'nespresso' + assert.equal(eventUtil.elementHasDataset(node, datasetToTest), true) + }) + it('can not accept partial string match', function () { + datasetToTest = ['nespressomnibox'] + assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false) + }) + it('returns false if node do not provide a dataset', function () { + node = delete node.dataset + datasetToTest = ['nespresso'] + assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false) + }) + }) +})