Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: select-field not showing in correct place #1400

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/select/src/select/menu-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const MenuWrapper = ({
selectRef,
}) => {
return (
<Layer onBackdropClick={onClick} transparent>
<Layer onBackdropClick={onClick} transparent disablePortal>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main question is whether disablePortal for menu-wrapper (which is only used internally by Select) has some side effects I am unaware of - I can't think why this specific use case (showing the list of the Select) would need a portal?

<Popper
reference={selectRef}
placement="bottom-start"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Position of SelectField

Scenario: Keeps position when parent is hidden initially
Given a Select is hidden initially
When someone hovers over it to show it
And clicks the select
Then the select dropdown should be in the correct position
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Given, Then, When } from '@badeball/cypress-cucumber-preprocessor'

Given('a Select is hidden initially', () => {
cy.visitStory('SingleSelectField', 'With hidden parent')
})

When('someone hovers over it to show it', () => {
cy.get('.container .hiddenSelect').invoke('attr', 'style', 'display: block')
})

When('clicks the select', () => {
cy.get('[data-test="dhis2-uicore-select"]').click()
})

Then('the select dropdown should be in the correct position', () => {
cy.get('[data-test="hoverable-select-field"]').should('be.visible')
cy.get('[data-test="dhis2-uicore-singleselectoption"]').should(
($selectField) => {
const { top, left } = $selectField.offset()
expect(top).to.be.greaterThan(0)
expect(left).to.be.greaterThan(0)
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,42 @@ export const WithFilterable = () => (
)
export const WithLoading = () => <SingleSelectField loading />
export const WithoutOptions = () => <SingleSelectField />

export const WithHiddenParent = () => {
return (
<>
<div className="container">
<div className="hoverSpan">
<span>Hover over me</span>
<div className="hiddenSelect">
<SingleSelectField
dataTest="hoverable-select-field"
label="Choose something"
onChange={() => {}}
>
<SingleSelectOption value="1" label="one" />
<SingleSelectOption value="2" label="two" />
</SingleSelectField>
</div>
</div>
</div>
<style jsx>{`
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 1rem;
}
.hiddenSelect {
display: none;
}
.hoverSpan:hover .hiddenSelect {
display: block;
}
`}</style>
</>
)
}
Loading