Skip to content

Commit

Permalink
Extend IdeaDropTarget to allow custom tagName
Browse files Browse the repository at this point in the history
  - shift default from section -> div
    - this shift caused a styling regression for overflowed list within the CategoryColumn, due to us using the 'section' css selector, which may have once been necessary for specificity (overriding semantic ui's default styles), but we safely removed this selector, as the classname selector that it was paired with does the trick on its own
  • Loading branch information
vanderhoop committed Feb 11, 2019
1 parent 570ac29 commit 64f3c35
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
24 changes: 23 additions & 1 deletion test/components/idea_drop_target_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@ describe("IdeaDropTarget", () => {
const defaultProps = {
onDropOfIdea: () => {},
dragAndDropHandlersActive: true,

}

it("renders a div wrapping element by default", () => {
wrapper = shallow(
<IdeaDropTarget
{...defaultProps}
/>
)

expect(wrapper.html()).to.match(/^<div /)
})

context("when a tagName is specified", () => {
it("renders the wrapping element with the specified tagName", () => {
wrapper = shallow(
<IdeaDropTarget
{...defaultProps}
tagName="li"
/>
)

expect(wrapper.html()).to.match(/^<li /)
})
})

context("when dragAndDropHandlersActive is true", () => {
it("applies drag and drop handlers", () => {
wrapper = shallow(
Expand Down
2 changes: 1 addition & 1 deletion web/static/js/components/css_modules/category_column.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import '../../../css/colors.css';

:global(section.column).index {
:global(.column).index {
--inner-column-padding: 0.75rem;
&:first-of-type { padding-right: var(--inner-column-padding) !important; }
&:last-of-type { padding-left: var(--inner-column-padding) !important; }
Expand Down
13 changes: 9 additions & 4 deletions web/static/js/components/idea_drop_target.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class IdeaDropTarget extends Component {

render() {
const { handleDragOver, handleDrop, handleDragLeave, props, state } = this
const { children, wrapperClassName, dragAndDropHandlersActive } = props
const { tagName, children, wrapperClassName, dragAndDropHandlersActive } = props

const className = classNames(wrapperClassName, {
"dragged-over": state.draggedOver,
Expand All @@ -48,26 +48,31 @@ export class IdeaDropTarget extends Component {
onDrop: handleDrop,
} : {}

// React requires a Capitalized constant
const WrappingElement = tagName

return (
<div
<WrappingElement
className={className}
{...dragAndDropHandlers}
>
{children}
<span className="overlay" />
</div>
</WrappingElement>
)
}
}

IdeaDropTarget.propTypes = {
onDropOfIdea: PropTypes.func.isRequired,
dragAndDropHandlersActive: PropTypes.bool,
onDropOfIdea: PropTypes.func.isRequired,
tagName: PropTypes.string,
wrapperClassName: PropTypes.string,
}

IdeaDropTarget.defaultProps = {
dragAndDropHandlersActive: true,
tagName: "div",
wrapperClassName: "",
}

Expand Down

0 comments on commit 64f3c35

Please sign in to comment.