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(cdk/drag-drop): avoid conflicts with sticky table headers #22864

Merged

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 3, 2021

The Material table with sticky headers sets its position as !important which ends up overriding the dragging styles. These changes rework the internals to use setProperty instead of element.style.position which allows us to set the position as !important as well. It also has the advantage that we can write the properties as dash case, instead of having to guess whether the vendor-prefixed properties are camel case or pascal case.

Fixes #22781.

The Material table with sticky headers sets its `position` as `!important` which ends up overriding the dragging styles. These changes rework the internals to use `setProperty` instead of `element.style.position` which allows us to set the `position` as `!important` as well. It also has the advantage that we can write the properties as dash case, instead of having to guess whether the vendor-prefixed properties are camel case or pascal case.

Fixes angular#22781.
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jun 3, 2021
@crisbeto crisbeto requested a review from jelbourn June 3, 2021 06:33
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 3, 2021
@brendanowens
Copy link

Thank you for the quick fix on this @crisbeto!

Comment on lines +91 to +96
/** Inline styles to be set as `!important` while dragging. */
const dragImportantProperties = new Set([
// Needs to be important, because some `mat-table` sets `position: sticky !important`. See #22781.
'position'
]);

Copy link
Member

@jelbourn jelbourn Jun 21, 2021

Choose a reason for hiding this comment

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

How problematic would it be to alternatively remove the !important from mat-table? My inclination would be to avoid an !important arms race by avoiding it completely.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with removing the !important is that our sticky header selector currently has really low specificity and can be overwritten by styles that have been encapsulated by Angular. See #20558.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Jul 2, 2021
@wagnermaciel wagnermaciel merged commit 6cfb549 into angular:master Jul 9, 2021
wagnermaciel pushed a commit that referenced this pull request Jul 9, 2021
The Material table with sticky headers sets its `position` as `!important` which ends up overriding the dragging styles. These changes rework the internals to use `setProperty` instead of `element.style.position` which allows us to set the `position` as `!important` as well. It also has the advantage that we can write the properties as dash case, instead of having to guess whether the vendor-prefixed properties are camel case or pascal case.

Fixes #22781.

(cherry picked from commit 6cfb549)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(material/table): cdkDrag of mat-header-cell styling broken when used with "sticky: true"
4 participants